﻿var PageTemp = "";
var PageWork = ""
var PageStat = 0
var ExhibitionPhoto = 1

function GetXmlHttpObject(){
var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	  // Internet Explorer
		try {
		    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}



//  ********************************************************************
//  ********************************************************************
function SubscribeValidation(){
	
	if (Trim($('iName').value).length < 3){
		$('iName').focus()
		return false
	}

	if (Trim($('iEmail').value).length == 0){
		$('iEmail').focus()
		return false
	}
	else if (!RE.test(Trim($('iEmail').value))){
		$('iEmail').focus()
		return false
	}

	SaveSubscribe()
	return false
}


function SaveSubscribe(){

	xmlHttp= GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}

	$("subscribe1").className = "td-open";
	$("subscribe2").className = "td-close";
	$("subscribe3").className = "td-close";
	$("subscribe4").className = "td-close";

	$("mainpage").style.width = document.body.offsetWidth-22;
	$("mainpage").style.height = document.body.offsetHeight-22;
	$("mainpage").className = "td-open";

	url = "SubscribeNewSave.asp";
	url = url + "?username=" + $('iName').value + "&usermail=" + $('iEmail').value + "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange=stateChangedSaveSubscribe;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}


// ********************
// ********************
function stateChangedSaveSubscribe(){ 
	if (xmlHttp.readyState == 4){

		if (Right(xmlHttp.responseText,1) == 1){
			$("subscribe2").className = "td-open";
		}
		if (Right(xmlHttp.responseText,1) == 2){
			$("subscribe3").className = "td-open";
		}
		$("subscribe1").className = "td-close";

		frm = document.frmInvitation
		frm.Email.value = ""
		frm.Name.value = ""
		frm.Name.focus()

		$("mainpage").className = "td-close";
	}
}




//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
function SearchValidate(){
	txt = Trim($("qID").value)

	se = /%/i
	if (txt.length < 3 || txt.search(se)!=-1 || txt == "Search" || txt == "جستجو"|| txt == "بحث"){
		$("qID").focus();
		return false;
	}

	SearchProgress()
	return false
}

// ********************
// ********************
function SearchProgress(){

	xmlHttp= GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}

	if (PageTemp == ""){
		PageTemp = $("pagebody").innerHTML
		PageColor = $("pagebody").style.backgroundColor
	}
		

	$("plzwait").className = "td-open";

	$("mainpage").style.width = document.body.offsetWidth-22;
	$("mainpage").style.height = document.body.offsetHeight-22;
	$("mainpage").className = "td-open";

	url = "search.asp";
	url = url + "?q=" + Url.encode($('qID').value) + "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange=stateChangedSearchResult;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}


// ********************
// ********************
function stateChangedSearchResult(){ 
	if (xmlHttp.readyState == 4){
		$("pagebody").innerHTML = xmlHttp.responseText
		frm = document.frmSearch
		frm.q.value = "";
		$("pagebody").style.backgroundColor="#ffffff";
		$("pagebody").focus();
		$("mainpage").className = "td-close";
	}
}
// ********************
// ********************
function backtopage(){
	$("pagebody").innerHTML = PageTemp;
	$("pagebody").style.backgroundColor = PageColor;
}


// ********************
// ********************
function backtopage2(){
	$("ExSearchResult").innerHTML = PageWork;
}




//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
// ********************
// ********************
function showform(){
	if ($('frm1').className=='td-close')
		$('frm1').className='td-open'
	else{
		for (i=1; i<=3; i++)
			$("formmsg"+i).className = "td-close"
		$("formmsg4").className = "td-open"
		$('frm1').className='td-close'
		
		frm = document.frmOrder
		frm.firstname.value = ""
		frm.lastname.value = ""
		frm.email.value = ""
		frm.phone.value = ""
	}
}

function orderform(frm){
	for (i=1; i<=3; i++)
		$("formmsg"+i).className = "td-close"

	if (Trim(frm.lastname.value).length < 3){
		$("formmsg4").className = "td-close"
		$("formmsg1").className = "td-open"
		frm.lastname.focus()
		return false
	}

	if (Trim(frm.email.value).length == 0){
		$("formmsg4").className = "td-close"
		$("formmsg2").className = "td-open"
		frm.email.focus()
		return false
	}
	else if (!RE.test(Trim(frm.email.value))){
		$("formmsg4").className = "td-close"
		$("formmsg3").className = "td-open"
		frm.email.focus()
		return false
	}
	
	return true
}

//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
function CollectionDetail(picNumber,picName){
	if (picNumber=='1'){
		$("objectpic").src = "../images/collections/" + picName + "-3.jpg";
		$("objectpic").title = "Click to enlarge";
		$("collimg1").className = "collectiontiny1";
		$("collimg2").className = "collectiontiny2";
		$("collimg3").className = "collectiontiny2";
		$("nozoom").className = "td-close";
	}
	if (picNumber=='2'){
		$("objectpic").src = "../images/collections/" + picName + "-6.jpg";
		$("objectpic").title = "";
		$("collimg1").className = "collectiontiny2";
		$("collimg2").className = "collectiontiny1";
		$("collimg3").className = "collectiontiny2";
		$("nozoom").className = "td-open";
	}
	if (picNumber=='3'){
		$("objectpic").src = "../images/collections/" + picName + "-8.jpg";
		$("objectpic").title = "";
		$("collimg1").className = "collectiontiny2";
		$("collimg2").className = "collectiontiny2";
		$("collimg3").className = "collectiontiny1";
		$("nozoom").className = "td-open";
	}
//	return hs.close(this)
}





//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
function ExhibitionImages(mySel,myRow,myCount,FileName){
//	alert(myRow)
	for (i=1; i<=myCount; i++){
		$("ex-"+myRow+"-"+i).style.backgroundColor = "#b4a299";
		$("ex-"+myRow+"-"+i).style.cursor = "pointer";
	}
	$("ex-"+myRow+"-"+mySel).style.backgroundColor = "#9f7245";
	$("ex-"+myRow+"-"+mySel).style.cursor = "default";
	if (document.all) {
	    $("eximage-"+myRow).filters[0].Apply();
		$("eximage-"+myRow).filters[0].Play();
	}
	$("eximage-"+myRow).src = "../images/exhibitionobjects/" + FileName + "-2.jpg";
	
}



//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
function AdditionalPhoto(tedade,mode){
	if (mode==1){
		for (i=ExhibitionPhoto; i<=tedade; i++){
			if ($("additionalphoto").src != $("addphoto"+i).value && ExhibitionPhoto != i ){
				if (document.all) {
				    $("additionalphoto").filters[0].Apply();
					$("additionalphoto").filters[0].Play();
				}
				$("additionalphoto").src = $("addphoto"+i).value;
				ExhibitionPhoto = i;
				return false
			}
		}
	} else {
		if (ExhibitionPhoto > 1){
			if (document.all) {
			    $("additionalphoto").filters[0].Apply();
				$("additionalphoto").filters[0].Play();
			}
			$("additionalphoto").src = $("addphoto"+(ExhibitionPhoto-1)).value;
			ExhibitionPhoto = ExhibitionPhoto - 1 ;
			return false
		}
	}
}


//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
//  ********************************************************************
function SearchExhibition(){

	if (($('srYear').value == "Year" || $('srYear').value == "سال" || $('srYear').value == "سنة") && $('srCountry').value == "0" && ($('srName').value == "Artist Name" || $('srName').value == "نام هنرمند" || $('srName').value == "اسم الفنان")){
		$('srName').focus()
		return false;
	}

	if ($('srYear').value != "Year" && $('srYear').value != "سال" && $('srYear').value != "سنة"){
		if (!IsNumeric($('srYear').value) || $('srYear').value.length != 4){
			$('srYear').focus()
			return false;
		}
	}

	xmlHttp= GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}

	if (PageWork == "")
		PageWork = $("ExSearchResult").innerHTML

	$("searchwait").className = "td-open";
	$("ExSearchResult").innerHTML = "";

	$("mainpage").style.width = document.body.offsetWidth-22;
	$("mainpage").style.height = document.body.offsetHeight-22;
	$("mainpage").className = "td-open";

	url = "searchexhibition.asp";
		url = url + "?year=" + $('srYear').value + "&name=" + Url.encode($('srName').value) +"&country=" + $('srCountry').value + "&sid=" + Math.random();

//	alert(url)
	xmlHttp.onreadystatechange=stateChangedExhibitionResult;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// ********************
// ********************
function stateChangedExhibitionResult(){ 
	if (xmlHttp.readyState == 4){
		$("ExSearchResult").innerHTML = xmlHttp.responseText
		$("searchwait").className = "td-close";
		$("mainpage").className = "td-close";
	}
}
