function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getXMLHTTPRequest()
{//////////////setting up AJAX instance
	try
	{
		req = new XMLHttpRequest();
	}
	catch(err1)
	{
  		try
		{
  			req = new ActiveXObject("Msxml2.XMLHTTP");
  		}
		catch (err2)
		{
    		try
			{
    			req = new ActiveXObject("Microsoft.XMLHTTP");
    		}
			catch (err3)
			{
				document.write ('Your browser does not support AJAX');
      			req = false;
			}
 		}
	}
	return req;
}


function $(element) {
	return document.getElementById(element);
}

function enableCheck()
{
	$('availability').innerHTML='<a href=\"javascript:void(0);\" onclick=\"checkAvailability()\">Check Availability</a>';
	$('customers/customer_loginspan').innerHTML ="*";
	
}

function checkAvailability()
{
	var login = $('customers/customer_login').value;
	if (login.length >= 5)
	{
		$('customers/customer_loginspan').innerHTML = "*";
		var http1=getXMLHTTPRequest();
		var modurl=modurl="../../Views/customers/check_login.php";
		myRand=parseInt(Math.random()*999999999999999);
		modurl+= "?rand="+myRand+"&login_name="+login;
		try
		{
			http1.open("GET", modurl, true);
			http1.onreadystatechange = function()
												{
													if (http1.readyState == 4)
													{
														if(http1.status == 200)
														{
															if (http1.responseText.indexOf("SUCCESS")>=0)
															{
																$('availability').innerHTML="Login is Available";
															}
															else///means he was not logged in
															{
																$('availability').innerHTML="";
																$('customers/customer_loginspan').innerHTML="* Not Available. Please pick another login name.";
															}
														}
													}
													else
													{
														$('availability').innerHTML="Checking..";													
													}
												};
			http1.send(null);
		}
		catch(e)
		{
			http1.abort();
		}
	
	}
	else
	{
		$('customers/customer_loginspan').innerHTML = "* Length must be greater than 5";
	}
}

	function ShowResultsPage(ResultPage,PageNo)
	{
		location=ResultPage+"?PageNo="+PageNo;
	}
	function VisibleSearchFields(ctlName)
	{
		$(ctlName+'div').style.display="none";
		$(ctlName).style.display="inline";
	}


// we need to change the max min price values in search
// these max min values are stored as value of each option element
// in the select list. This function is called whenever teh selected
// element in select list is changed, and it saves the min and max values in
// two separate fields
function change_min_max(element) {
	//alert (element.value);
	var max_min = element.value.split(',');
	if (max_min[0]=='0') $('min_price').value= '';
	else $('min_price').value= max_min[0];
	if (max_min[1]=='0') $('max_price').value= '';
	else $('max_price').value= max_min[1];	
}

function SetMinPrice(ctlName)
{
	if ($('PriceRupee').checked)//if price range is in rupees
	{
		$('SearchField/txt/price_rupee1').value=ctlName.value;
		$('SearchField/txt/price1').value="";
	}
	else
	{
		$('SearchField/txt/price1').value=ctlName.value;
		$('SearchField/txt/price_rupee1').value="";
	}
}

function SetMaxPrice(ctlName)
{
	if ($('PriceRupee').checked)//if price range is in rupees
	{
		$('SearchField/txt/price_rupee2').value=ctlName.value;
		$('SearchField/txt/price2').value="";
	}
	else
	{
		$('SearchField/txt/price2').value=ctlName.value;
		$('SearchField/txt/price_rupee2').value="";
	}
}

function setPrices(ctlValue)
{
	switch (ctlValue)
	{
		case '1':
			$('SearchField/txt/priceleft1').value='0';
			$('SearchField/txt/priceleft2').value='499';
			break;
		case '2':
			$('SearchField/txt/priceleft1').value='500';
			$('SearchField/txt/priceleft2').value='1000';
			break;
		case '3':
			$('SearchField/txt/priceleft1').value='1000';
			$('SearchField/txt/priceleft2').value='5000';
			break;
		case '4':
			$('SearchField/txt/priceleft1').value='5000';
			$('SearchField/txt/priceleft2').value='10000';
			break;
		case '5':
			$('SearchField/txt/priceleft1').value='10000';
			$('SearchField/txt/priceleft2').value='50000';
			break;
		case '6':
			$('SearchField/txt/priceleft1').value='50000';
			$('SearchField/txt/priceleft2').value='';
			break;
		default:
			$('SearchField/txt/priceleft1').value='';
			$('SearchField/txt/priceleft2').value='';
			break;
	}
}
function SetDimensionHeight(ctlName)
{
	if ($('chkinch').checked)//if dimension in inches
	{
		if ($('chkframed').checked)///if framed dimensions
		{
			$('dimensions_framed_inches1').value=ctlName.value;
			$('dimensions_unframed_inches1').value="";
		}
		else
		{
			$('dimensions_unframed_inches1').value=ctlName.value;
			$('dimensions_framed_inches1').value="";			
		}
	}
	else
	{
		if ($('chkframed').checked)///if framed dimensions
		{
			$('dimensions_framed_inches1').value=ctlName.value*0.39;
			$('dimensions_unframed_inches1').value="";
		}
		else
		{
			$('dimensions_unframed_inches1').value=ctlName.value*0.39;
			$('dimensions_framed_inches1').value="";			
		}
	}
}

function SetDimensionWidth(ctlName)
{
	if ($('chkinch').checked)//if dimension in inches
	{
		if ($('chkframed').checked)///if framed dimensions
		{
			$('dimensions_framed_inches2').value=ctlName.value;
			$('dimensions_unframed_inches2').value="";
		}
		else
		{
			$('dimensions_unframed_inches2').value=ctlName.value;
			$('dimensions_framed_inches2').value="";			
		}
	}
	else
	{
		if ($('chkframed').checked)///if framed dimensions
		{
			$('dimensions_framed_inches2').value=ctlName.value*0.39;
			$('dimensions_unframed_inches2').value="";
		}
		else
		{
			$('dimensions_unframed_inches2').value=ctlName.value*0.39;
			$('dimensions_framed_inches2').value="";			
		}
	}
}

function FormColorScheme(ctlName)
{
	if (ctlName.checked)//if the chkbox is set
	{
		$('color_scheme').value+=ctlName.value;
	}
	else
	{
		$('color_scheme').value-=ctlName.value;
	}
}


//////////////add/remove to my gallery ajax call
function detectBrowser()
{
var browserName="";
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	{
		browserName="FF";
	}
	else if (navigator.appVersion.indexOf("MSIE")!=-1)
	{
		browserName="IE";
	}
	return browserName;
}

function updateMyGallery(divname,action,artworkid,callerid,old_url,pageno)
{
	if (typeof pageno == "undefined") pageno=1;
	var confirmAction=true;
	if (action=="remove")
	{
		var confirmAction=confirm("Are you sure to remove the art work from your gallery");
	}
	if (confirmAction===true)
	{
		var http1=getXMLHTTPRequest();
		var modurl=modurl="../../Views/includes/updateMyGallery.php";
		myRand=parseInt(Math.random()*999999999999999);
		modurl+= "?rand="+myRand+"&action="+action+"&artworkid="+artworkid;///for get request
		try
		{
			http1.open("GET", modurl, true);
			http1.onreadystatechange = function()
												{
													if (http1.readyState == 4)
													{
														if(http1.status == 200)
														{
															if (http1.responseText.indexOf("SUCCESS")>=0)
															{
																switch (action)
																{
																	case "add":
																		$(divname).className="already";
																		$(divname).innerHTML="";
																		break;
																	case "remove":
																		$("linkItems"+callerid).innerHTML="<img src=\"../../images/removed_item.gif\" style=\"border:0px\" >";
																		//$(divname).className="add";
																		break;
																}
															}
															else///means he was not logged in
															{
																document.location = "../../Views/customers/login.php?old_url="+old_url+"&PageNo="+pageno;
															}
														}
													}
													else
													{
														$(divname).className="adding";													
													}
												};
			http1.send(null);
		}
		catch(e)
		{
			http1.abort();
		}
	}
}

function Update0(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace0',action,artworkid,0,old_url,pageno);
}

function Update1(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace1',action,artworkid,1,old_url,pageno);
}

function Update2(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace2',action,artworkid,2,old_url,pageno);
}

function Update3(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace3',action,artworkid,3,old_url,pageno);
}

function Update4(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace4',action,artworkid,4,old_url,pageno);
}

function Update5(action,artworkid,old_url,pageno)
{
	var update4link=new updateMyGallery('addplace5',action,artworkid,5,old_url,pageno);
}


////////////////update artist

function updateMyArtist(divname,action,artistid,callerid,old_url,pageno)
{
	var confirmAction=true;
	if (action=="remove")
	{
		var confirmAction=confirm("Clicking on 'Ok' will remove this artist from your list, do you want to proceed?");
	}
	if (confirmAction===true)
	{
		var http1=getXMLHTTPRequest();
		var modurl=modurl="../../Views/includes/updateMyArtist.php";
		myRand=parseInt(Math.random()*999999999999999);
		modurl+= "?rand="+myRand+"&action="+action+"&artistid="+artistid;///for get request
		try
		{
			http1.open("GET", modurl, true);
			http1.onreadystatechange = function()
												{
													if (http1.readyState == 4)
													{
														if(http1.status == 200)
														{
															if (http1.responseText.indexOf("SUCCESS")>=0)
															{
																switch (action)
																{
																	case "add":
																		$(divname).innerHTML="recently added in my artists";
																		break;
																	case "remove":
																		$(divname).innerHTML="recently removed from my artists";
																		//$("ArtistRow"+callerid).style.display="none";
																		break;
																}
															}
															else///means he was not logged in
															{
																document.location = "../../Views/customers/login.php?old_url="+old_url+"&PageNo="+pageno;
															}
														}
													}
													else
													{
														$(divname).innerHTML="<image src=\"../../images/loader.gif\" border=\"0\">";													
													}
												};
			http1.send(null);
		}
		catch(e)
		{
			http1.abort();
		}
	}
}

function UpdateArtist(action,artistid,callerid,old_url,pageno)
{
	var UpdateArtist4link=new updateMyArtist('addartistplace'+callerid,action,artistid,callerid,old_url,pageno);
}
