var xmlHttp;

function loadmap(strMap){
		//document.getElementById("MyMap").innerHTML = '<img src="'+strMap+'" border="0" usemap="#Map" />';
		document['gccMap'].src=strMap;
}

/*function show(id){
		document.getElementById(id).style.display="";
	}

function hide(id){
		document.getElementById(id).style.display="none";
}*/

function fillKey(){
	alert("asdasd");
	document.form1.person.value="Nisal";		
}

function Toggle(id){
	if(document.getElementById(id).style.display=="none"){
		document.getElementById(id).style.display="block";	
	}else{
		document.getElementById(id).style.display="none";	
	}
}


function JumpTo(page, url){
	//window.frmCompanySearch.action;
	document.frmSearch.action=url;
	document.frmSearch.Page.value = page; 
	document.frmSearch.submit();
}

function getText(source, target){
	var selectedItem =document.frmSearch[source].selectedIndex;
	var selectedText = document.frmSearch.Country.options[selectedItem].text; // document.choiceForm.available.options[selectedItem].text;
	var selectedValue = document.frmSearch.Country.options[selectedItem].value; //document.choiceForm.available.options[selectedItem].value;
	document.frmSearch[target].value = selectedText;
}

function getTextQuick(source, target){
	var selectedItem =document.frmBrand[source].selectedIndex;
	var selectedText = document.frmBrand.Country.options[selectedItem].text; // document.choiceForm.available.options[selectedItem].text;
	var selectedValue = document.frmBrand.Country.options[selectedItem].value; //document.choiceForm.available.options[selectedItem].value;
	document.frmBrand[target].value = selectedText;
}
function submitQuickCompany(source, target){
	var selectedItem =document.frmQuickSearch[source].selectedIndex;
	var selectedText = document.frmQuickSearch.Country.options[selectedItem].text; // document.choiceForm.available.options[selectedItem].text;
	var selectedValue = document.frmQuickSearch.Country.options[selectedItem].value; //document.choiceForm.available.options[selectedItem].value;
	document.frmQuickSearch[target].value = selectedText;
}

function submitQuickCountry(country, text){
	//document.frmCountry.CountryText.value 	= text;
	//document.frmCountry.Country.value 	= "'"+country+"'";
	//document.frmCountry.submit();
	window.location.href=text+"cnt-"+country;
}
function text(str){
	document.getElementById('fixedtipdiv').innerHTML='<b>Hello:<br>'+str;	
}


function getCategoryAds(baseUrl, code){
	document.getElementById('fixedtipdiv').style.visibility="hidden";
	
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
  	alert ("Your browser does not support AJAX!");
  	return;
	}	
	var divHeader = '<table border="0" class="catTbl" cellpadding="1" cellspacing="0"><tr><td height="18" align="left" class="catTitle">&nbsp;&nbsp;<strong class="blackFont" >Click on the bellow links for view advertisements</strong></td><td align="right" class="catTitle">&nbsp;&nbsp;<a href="javascript:delayhidetip()"><strong>x</strong></a>&nbsp;&nbsp;</td></tr><tr><td colspan="2" style="padding:5px;" >';
	xmlHttp.onreadystatechange = function(){
   		//Check page is completed and there were no problems.
		if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
			document.getElementById('fixedtipdiv').innerHTML=divHeader+xmlHttp.responseText+'</td></tr></table>';
		}else{
			document.getElementById('fixedtipdiv').innerHTML='<table border="0" class="catTbl" cellpadding="1" cellspacing="0"><tr><td height="18"><img src="'+baseUrl+'/pictures/furniture/ajax-loader.gif" /> Please wait...</td></tr></table>';
		}
    }
	var url=baseUrl+"index.php/webdirectory/categoryAds/"+code;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function getMainCategory(baseUrl ,str, page, strContainer){ 
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
  	alert ("Your browser does not support AJAX!");
  	return;
	} 
	
	document.getElementById('SubCatText').value='All Categories';
	xmlHttp.onreadystatechange = function(){
   		//Check page is completed and there were no problems.
		if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
			document.getElementById(strContainer).innerHTML=xmlHttp.responseText;
		}else{
			document.getElementById(strContainer).innerHTML="<img src='"+baseUrl+"/pictures/furniture/ajax-loader.gif' />";
		}
    }
	if(str==""){
		var url=baseUrl+"index.php/WebDirectory/fillSubCategory/0";
	}else{
		var url=baseUrl+"index.php/WebDirectory/fillSubCategory/"+str;
	}
	//alert(url);
	//url=url+"&sid="+Math.random();
	//xmlHttp.onreadystatechange=stateChanged(strContainer);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitMainProduct(str){
	document.frmSearch1.MainCategory.value=str;
	document.frmSearch1.submit();
}

function submitProduct(str){
	document.frmSearch1.SubCategory2.value=str;
	document.frmSearch1.submit();
}

function Collaps(id){
	if(document.getElementById(id).style.display=="none"){
		document.getElementById(id).style.display="block";	
	}else{
		document.getElementById(id).style.display="none";	
	}
	//document[img_name].src=	
}

function ResetForm(mod){
	if((mod=='Company') || (mod=='Advanced')){
		document.frmSearch.CompanyName.value="";
		ClearCountry()
	}
}

function ClearCountry(){
	var boxLength = document.frmSearch.Country.length;
	var i;
	for (i = 0; i < boxLength; i++) {
			thisitem = document.frmSearch.Country.options[i].text;
			if (thisitem == 'All Countries') {
				document.frmSearch.Country.options[i].selected = true;
			}else{
				document.frmSearch.Country.options[i].selected = false;	
			}
	}
}

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;
}

var popUpWin=0;
function popUpWindow(URLStr, width, height){
	var left, top;
	left = (screen.width/2)-(width/2);
	top  = (screen.height/2)-(height/2);
  if(popUpWin) {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function PopupPic(url,sPicURL) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	//popUpWin = open(url+"/popup.htm?"+sPicURL, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=1,copyhistory=yes,width=100,height=40,left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin = open( url+"pictures/popup.htm?"+sPicURL, "popUpWin", "resizable=1,HEIGHT=50,WIDTH=50,LEFT=100, TOP=250, screenX=100,screenY=250");
}
function closeDivAd(){
	document.getElementById('divAdd').style.display='none';	
}

function ShowAddInDIV(url, sPicURL ){
	var img   = url+"pictures/company/advts/"+sPicURL;
	//var img1 = image.width;
	//alert(img1);
	document.getElementById('divAdd').style.top='100px';
	document.getElementById('divAdd').style.left='400px';
	document.getElementById('divAdd').style.display="block";
	document.getElementById('divAdd').innerHTML='<a href="javascript:closeDivAd();" class="BlackLink" style="padding:0px 3px 3px 0px"><b>Close Advertisement</b></a><br><img src="'+img+'" />';
}

function chekcForm(objForm){
	var count = 0;
	elLength =objForm.length; 
	for(i=0; i<elLength;i++) {
		if((objForm[i].type=="text") && (objForm[i].name=="CompanyName")){
			count=objForm[i].value.length;
		}else if((objForm[i].type=="text") && (objForm[i].name=="Brand")){
			count=objForm[i].value.length;	
		}
	}
	if((count>1) || (count==0)){
		return true;	
	}else{
		alert("Please enter a minimum of 2 characters in the search field.");
		return false;
	}
}

//****************************************************************
//----------- Back End ----------------------------------
function checkID(baseUrl, obj, field, table, dir){
	//document.getElementById('divMessage').style.visibility="block";
	var code = document.getElementById(obj).value;
	if(code!=""){
		xmlHttp=GetXmlHttpObject();
	
		if (xmlHttp==null) {
			alert ("Your browser does not support AJAX!");
			return;
		}	
		//var divHeader = '<table border="0" class="catTbl" cellpadding="1" cellspacing="0"><tr><td height="18" align="left" class="catTitle">&nbsp;&nbsp;<strong class="blackFont" >Available Advertisements</strong></td><td align="right" class="catTitle">&nbsp;&nbsp;<a href="javascript:delayhidetip()"><strong>x</strong></a>&nbsp;&nbsp;</td></tr><tr><td colspan="2" style="padding:5px;" >';
		xmlHttp.onreadystatechange = function(){
			//Check page is completed and there were no problems.
			if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
				document.getElementById('divMessage').innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById('divMessage').innerHTML='<img src="'+baseUrl+'/pictures/furniture/ajax-loader.gif" />';
			}
		}
		var url=baseUrl+"index.php/directorycontrolpanel/checkIDAvailable/"+code+"/"+field+"/"+table+"/"+dir;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function checkCompID(baseUrl){
	//document.getElementById('divMessage').style.visibility="block";
	var code = document.getElementById('comID').value;
	if(code!=""){
		xmlHttp=GetXmlHttpObject();
	
		if (xmlHttp==null) {
			alert ("Your browser does not support AJAX!");
			return;
		}	
		//var divHeader = '<table border="0" class="catTbl" cellpadding="1" cellspacing="0"><tr><td height="18" align="left" class="catTitle">&nbsp;&nbsp;<strong class="blackFont" >Available Advertisements</strong></td><td align="right" class="catTitle">&nbsp;&nbsp;<a href="javascript:delayhidetip()"><strong>x</strong></a>&nbsp;&nbsp;</td></tr><tr><td colspan="2" style="padding:5px;" >';
		xmlHttp.onreadystatechange = function(){
			//Check page is completed and there were no problems.
			if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
				document.getElementById('divMessage').innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById('divMessage').innerHTML='<img src="'+baseUrl+'/pictures/furniture/ajax-loader.gif" />';
			}
		}
		var url=baseUrl+"index.php/directorycontrolpanel/checkCompanyIDAvailable/"+code;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function jumpPage(url){
	document.form1.action=url;
	document.form1.submit();
}

function getSelectredText(source, target){
	//objForm = document.getElementById(frm);
	var selectedItem 	= document.getElementById(source).selectedIndex;
	var selectedText 	= document.getElementById(source).options[selectedItem].text; // document.choiceForm.available.options[selectedItem].text;
	var selectedValue 	= document.getElementById(source).options[selectedItem].value; //document.choiceForm.available.options[selectedItem].value;
	document.getElementById(target).value = selectedText;
}

function show(id){
		document.getElementById(id).style.display="";
}

function hide(id){
		document.getElementById(id).style.display="none";
}