// JavaScript Document

var xmlHttp

 function WaitOn() {
	document.body.style.cursor="wait";
}

 function WaitOff() {
	document.body.style.cursor="auto";
}
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("NO_AJAX");
	}
}

function GetXmlHttpObject(handler) { 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0) {
		/*alert("This example doesn't work in Opera") 
		return */
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		} 
		try	{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} catch(e)	{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0) {
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}
var xml_Https;
	
	function EmptyCities() 
	{
		document.getElementById("city").options.length = 0;
	}
	
	function Emptystates() 
	{
		document.getElementById("state").options.length = 0;
	}
	
	function showcity_other(str)
	{
		//document.buy1.country_hidd.value=document.buy1.country.options[document.buy1.country.selectedIndex].text;
		//document.buy1.state_hidd.value=document.buy1.state.options[document.buy1.state.selectedIndex].text;
		document.getElementById("state_hidd").value=document.getElementById("state").options[document.getElementById("state").selectedIndex].text;
		if (str == '-1') {
			 document.getElementById("city_other").style.display="block";
			 document.getElementById("city_other").value="Enter City";
			 document.getElementById("zip_other").style.display="block";
			 document.getElementById("zip_other").value="Zip/Postal Code";
		}
		else
		{
			document.getElementById("city_other").style.display="none";
			document.getElementById("zip_other").style.display="none";
		}
	}
	
	function showstates(str)
	{
		if (str == '-1') {
			 return;
		}
		else
		{
			document.getElementById("state_other").style.display="none";
			document.getElementById("city_other").style.display="none";
			document.getElementById("zip_other").style.display="none";
		}
		Emptystates();	
		EmptyCities();		
		if (str.length == 0) {
		document.getElementById("state").options[0] = new Option("Choose a State","");	
		document.getElementById("city").options[0] = new Option("Choose a City","");
			return;
		}
		WaitOn();		
		if(window.location.href.match("ECmemberdetails.php"))
		{
			var url="../ajax/ajaxcity.php?sid=" + Math.random() + "&countryid=" + str
		}else
		{
		var url="ajax/ajaxcity.php?sid=" + Math.random() + "&countryid=" + str
		}
		xml_Https=GetXmlHttpObject(countryChanged)
		xml_Https.open("GET", url , true)
		xml_Https.send(null)
		
	}
	
	
	function countryChanged() { 
		
		if (xml_Https.readyState==4 || xml_Https.readyState=="complete") { 

			var xml_Httpsresp=xml_Https.responseText;
			var val=false;
			var arrxml = xml_Httpsresp.split("<delim>");
			var cities = arrxml[0];
			var arrCities=cities.split("|");
			document.getElementById("city").options[0] = new Option("Choose a City","");
			if(parseInt(document.getElementById("country").options[document.getElementById("country").selectedIndex].value)!=223)
				document.getElementById("state").options[0] = new Option("Choose a State/Province","");
			else
				document.getElementById("state").options[0] = new Option("Choose a State","");
				
			for (i=0;i<arrCities.length-1;i++) {
				if (arrCities[i].length>0) {
					var arrCities_split = arrCities[i].split("/");
					document.getElementById("state").options[i+1] = new Option(arrCities_split[1],arrCities_split[0]);
					if(arrCities_split[2]=='223')
					{
						val=true;
					}
				}
			}
			if(!val)
			{
				//document.getElementById("city").options[i+1] = new Option("Other","-1");
				document.getElementById("state").options[i+1] = new Option("Other","-1");
			}
			WaitOff();		
		} 
	
	} 
	
	function showCities(str)
	{
		 EmptyCities();
		 if (str == '-1') {
			 document.getElementById("state_other").style.display="block";
			 document.getElementById("state_other").value="Enter State";
			 document.getElementById("city_other").style.display="block";
			 document.getElementById("city_other").value="Enter City";
			 document.getElementById("zip_other").style.display="block";
			 document.getElementById("zip_other").value="Zip/Postal Code";
			 document.getElementById("city").options[0] = new Option("Choose a City","");
			 document.getElementById("city").options[1] = new Option("Other","-1");
			 document.getElementById("city").options[1].selected="selected";
			return;
		}
		else
		{
			document.getElementById("state_other").style.display="none";
			document.getElementById("city_other").style.display="none";
			document.getElementById("zip_other").style.display="none";
		}
		
		
		
	    if (str.length == 0) {
			document.getElementById("city").options[0] = new Option("Choose a City","");
			var sel_cnt=document.getElementById("country");
			if(sel_cnt.options[sel_cnt.selectedIndex].value!='223')
			{
				document.getElementById("city_other").style.display="none";
				document.getElementById("zip_other").style.display="none";
			}
			return;
		}
		
		WaitOn();		
		if(window.location.href.match("ECmemberdetails.php"))
		{
		var url="../ajax/ajaxcity.php?sid=" + Math.random() + "&stateid=" + str
		}else
		{
			var url="ajax/ajaxcity.php?sid=" + Math.random() + "&stateid=" + str
		}
		xmlHttp=GetXmlHttpObject(stateChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
		
	}
	
	function stateChanged() { 
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 

			var xmlresp=xmlHttp.responseText;
			var val=false;
			//alert(xmlresp);
			var arrxml = xmlresp.split("<delim>");
			var cities = arrxml[0];
			var arrCities=cities.split("|");
			document.getElementById("city").options[0] = new Option("Choose a City","");
			for (i=0;i<arrCities.length-1;i++) {
				if (arrCities[i].length>0) {
					var arrCities_split = arrCities[i].split("/");
					document.getElementById("city").options[i+1] = new Option(arrCities_split[1]+" : "+arrCities_split[2],arrCities_split[0]);
					if(arrCities_split[3]=='223')
					{
						val=true;
					}
				}
			}
			if(!val)
			{
				document.getElementById("city").options[i+1] = new Option("Other","-1");
			}
			WaitOff();		
		} 
	
	} 
function popUpsize(URL,width,height) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=" + width + ",height=" + height + ",left = 90,top = -20');");
}
	
	
var xmllHttp;
var content_to_div;
var towindow=1;
var cur_url;
function ajaxclik(url,div_to,to_window)
{
		WaitOn();
		content_to_div=div_to;	
		cur_url=url;
		if(to_window)
		  towindow=to_window;
		else
		  towindow=1;
		xmllHttp=GetXmlHttpObject(showallpg)
		xmllHttp.open("GET", url , true)
		xmllHttp.send(null)
}
function showallpg()
{
	if (xmllHttp.readyState==4 || xmllHttp.readyState=="complete")
	 { 
		var s =xmllHttp.responseText;
		if(content_to_div=="full_page")
		{
			$('#img_tags').remove();
		}
		//s = s.replace(/\s/g, ' ');
		s = s.replace(new RegExp('^.*?<body[^>]*>(.*?)</body>.*?$', 'i'), '$1');
		switch(towindow)
		{
		case 1:	
			 window.parent.document.getElementById(content_to_div).innerHTML = s;
			 fadesIn(document.getElementById(content_to_div), 0);
		break;
		case 2:	
			 window.parent.document.getElementById(content_to_div).innerHTML = s;
			 if(window.parent.hs && cur_url.match("new_photo_comments.php"))
			 {
				 window.parent.hs.close();
			 }
		break;
		case 4:	
			window.parent.document.getElementById(content_to_div).innerHTML = s;
			//var url="web_info_music.php?sid=" + Math.random();ajaxclik(url,"div_music",3);
		break;
		case 5:	
			document.getElementById(content_to_div).innerHTML = s;
			var url="web_info_music.php?sid=" + Math.random();ajaxclik(url,"div_music",3);
		break;
		case 3:	
		    window.top.document.getElementById(content_to_div).innerHTML = s;
		break;
		case 6:	
		    window.parent.document.getElementById(content_to_div).innerHTML = s;
			var image_id=document.getElementById("image_id").value;
			var url="new_photo_comments.php?img_id="+image_id+"&exchange=yes";ajaxclik(url,"new_photo_comnts",8);
		break;
		case 7:	
		    window.parent.document.getElementById(content_to_div).innerHTML = s;
			var image_id=document.getElementById("image_id").value;
			var url="new_photo_comments.php?img_id="+image_id;ajaxclik(url,"new_photo_comnts",8);
		break;
		case 8:	
		   window.parent.parent.document.getElementById(content_to_div).innerHTML = s;
		   if(window.parent.hs && cur_url.match("new_photo_comments.php"))
			 {
				 window.parent.hs.close();
			 }
		break;
		case 100:	
			window.parent.document.getElementById(content_to_div).innerHTML = s;
			light_bulb_after(document.getElementById('lbulb_off'));
		break;
		
		default :
		    document.getElementById(content_to_div).innerHTML = s;
		break;
		}
		WaitOff();		
	}
}
function fadesIn(element, opacity) {
	var reduceOpacityBy = 5;
	var rate = 30;	// 15 fps

	if (opacity < 100) {
		opacity += reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity < 100) {
		setTimeout(function () {
			fadesIn(element, opacity);
		}, rate);
	}
}


var chkavail=getXmlHttpRequestObject();
function delete_pic(delete_id,prev_id_sel,next_id_sel,my_u)
{
if(confirm('Are you sure you want to delete the picture?'))
{
	//document.getElementById('delete_id').value=delete_id;
	WaitOn();
	var url="ajax/ajaxcity.php?sid=" + Math.random() + "&delete_img_id=" +delete_id;
	chkavail.onreadystatechange = function()
	{
		if (chkavail.readyState==4 || chkavail.readyState=="complete")
		{ 
	
			var ajaxresp=chkavail.responseText;
			if(document.getElementById("class_"+delete_id).parentNode.id!="chromemenu")
			{
				if(prev_id_sel || next_id_sel)
				{
					if(next_id_sel)
					{
						$('#slideshow').trigger('next');
						previousof(this,delete_id,'next-delete',my_u);
					}
					else
					{ 
						$('#slideshow').trigger('prev');
						previousof(this,delete_id,'prev-delete',my_u);
					}
					document.getElementById("class_"+delete_id).parentNode.parentNode.removeChild(document.getElementById("class_"+delete_id).parentNode);
				}
				else
				{
					window.location='user_photos.php'
				}
			}
			else
				document.getElementById("class_"+delete_id).parentNode.removeChild(document.getElementById("class_"+delete_id));
			WaitOff();		
	
		}
	}
	chkavail.open("GET", url , true)

	chkavail.send(null)
}
else
	return false;
}
function successful_delete_image()
{
	if (chkavail.readyState==4 || chkavail.readyState=="complete")
	{ 

		var ajaxresp=chkavail.responseText;
		WaitOff();		

	} 
}


function null_input(given_id,thisvalue,comparewith)
{
	if(thisvalue==comparewith)
	{
		given_id.value="";
	}
}	
function use_thumb(img_id,collection_id,type)
{
WaitOn();
switch(type)
{
	case 'exchange':
			var url="ajax/ajaxcity.php?sid=" + Math.random() + "&img_id=" + img_id+"&saveview_id="+collection_id;
			break;
	case 'user':
			var url="ajax/ajaxcity.php?sid=" + Math.random() + "&img_id=" + img_id+"&collection_id="+collection_id;
			break;
}
chkavail=GetXmlHttpObject(collection_thumb_set)

	chkavail.open("GET", url , true)

	chkavail.send(null)
}

function collection_thumb_set()
{ 

	if (chkavail.readyState==4 || chkavail.readyState=="complete")

	{ 

		var ajaxresp=chkavail.responseText;
		//document.getElementById("chk_avail").innerHTML=ajaxresp;

		WaitOff();		

	} 

} 
function remove_pic(delete_id,collect_id,type)
{
if(confirm('Are you sure you want to remove the picture?'))
{
	//document.getElementById('delete_id').value=delete_id;
	WaitOn();
	switch(type)
	{
		case 'user':
			var url="ajax/ajaxcity.php?sid=" + Math.random() + "&remove_img=" +delete_id+"&collect="+collect_id;
			break;
		case 'exchange':	
			var url="ajax/ajaxcity.php?sid=" + Math.random() + "&remove_img=" +delete_id+"&ex_collect="+collect_id;
			break;
	}
	chkavail=GetXmlHttpObject(successful_remove_image)

	chkavail.open("GET", url , true)

	chkavail.send(null)
}
else
	return false;
}
function successful_remove_image()
{
		if (chkavail.readyState==4 || chkavail.readyState=="complete")

	{ 

		var ajaxresp=chkavail.responseText;
		parent.window.location.reload();

		WaitOff();		

	} 
}

function add_to_cart(image_id,collect_id,exc)
{

	if(image_id!=0 && image_id!="")
		typeOfCart=1;
	else
		typeOfCart=0;
	
		
	
	WaitOn();
	if(exc==1)
		var url="addtocart.php?image_id=" + image_id + "&collection_id=" +collect_id+"&exc=1";
	else
		var url="addtocart.php?image_id=" + image_id + "&collection_id=" +collect_id;
		
	chkavail=GetXmlHttpObject(successful_add_cart)

	chkavail.open("GET", url , true)

	chkavail.send(null)

}

function successful_add_cart()
{
		if (chkavail.readyState==4 || chkavail.readyState=="complete")

	{ 

		var ajaxresp=chkavail.responseText;
		
		if(ajaxresp=="imgExist" )
			alert("The image already added in the cart");
		else if(ajaxresp=="colExist" )
			alert("The collection already added in the cart");
		else if(ajaxresp=="img")
			alert("Successfully added to the cart");
		else
			alert("Successfully added to the cart");
		

		WaitOff();		

	} 
}



function print_pic(print_id,type)
{

	//document.getElementById('delete_id').value=delete_id;
	WaitOn();
	
	var url="ajax/ajaxcity.php?sid=" + Math.random() + "&print_img=" +print_id+ "&type=" +type;
	
	chkavail=GetXmlHttpObject(successful_print_image)

	chkavail.open("GET", url , true)

	chkavail.send(null)

}
function successful_print_image()
{
		if (chkavail.readyState==4 || chkavail.readyState=="complete")

	{ 

		var ajaxresp=chkavail.responseText;
		
		if(ajaxresp=="exist" )
			alert("The image already added to print");
		else if(ajaxresp=="img")
			alert("Successfully added to print");
		

		WaitOff();		

	} 
}

var div_id;
function exc_request_invite(excid,userid,divid)
{
	div_id=divid;
	WaitOn();
	var url="ajax/ajaxcity.php?sid=" + Math.random() + "&invite_exc=" + excid+"&invite_usr="+userid;
	chkavail=GetXmlHttpObject(exc_requested)
	chkavail.open("GET", url , true)
	chkavail.send(null);
	return false;
}
function exc_requested()
{ 

	if (chkavail.readyState==4 || chkavail.readyState=="complete")
	{ 

		var ajaxresp=chkavail.responseText;
		document.getElementById(div_id).innerHTML=ajaxresp;
		WaitOff();		

	} 

} 

