var spellUrl = 'SELF'; // URL to spell_checker.php
//-------------------- Get Cities List -------------------------------
var globalField = '';		//
var globalFile = '';			//
var globalGetCodes = '';		//

function enableDisable(fieldName, bool){
	document.getElementById(fieldName).disabled = bool;
}

function getCitiesList_cb(new_data)
{

	//alert(new_data);
	var str = new_data;
	pstr = str.split("||");
	var rsSpan = pstr[0];			// resulted Span
	var rsCity = pstr[1];			// User's City Name
	var rsCountryCode = pstr[2];	// Country Code
	var rsString = pstr[3];			// resulted String
	var browser = pstr[4];			// User's Browser
	var ccH = pstr[5];			
	var ccM = pstr[6];			

	document.getElementById(rsSpan).innerHTML = rsString;	
	enableDisable(globalField, false)

	if(globalGetCodes=='Y')
	{		
		var cH = ( ccH!="undefined" && ccH!='' ? ccH : 'su_countryCodeHomePhone' );
		var cM = ( ccM!="undefined" && ccM!='' ? ccM : 'su_countryCodeMobile' );
		
		document.getElementById(cH).value = rsCountryCode;
		document.getElementById(cM).value = rsCountryCode;
	}
	return true;
}

function getCitiesList (countryField, cityFieldName, userCityName, resultSpan, returnFile, getCodes,mobSpan,mobID,cityCodeID,cls,ccH,ccM,ctySpan,mobVal)
{
	ctCls = cls;

	var countryName = document.getElementById(countryField).value;
	document.getElementById(resultSpan).innerHTML = "<select name='"+cityFieldName+"' id='"+cityFieldName+"' style='font-family:verdana; font-size: 11px; width: 120px' disabled><option value=''>Processing....</option></select>";
	globalGetCodes = getCodes;
	globalField = countryField;
	globalFile = returnFile;
	enableDisable(globalField, true);

	if(globalGetCodes == 'Y')
		setOtherCodes(countryField,mobSpan,mobID,cityCodeID,ctCls,mobVal);
	cpaint_call (returnFile, 'POST', 'getCitiesList',countryName, cityFieldName, userCityName, resultSpan,globalGetCodes,countryField,cityCodeID,ctySpan,returnFile,cls,ccH,ccM, getCitiesList_cb);
	
	return false;
}

function setOtherCodes(ctFld,mobSpan,mobID,ctyCode,ctCls,mobVal){

	var fld = ( typeof ctFld!="undefined" && ctFld!='' ? ctFld : 'su_country' );
	var spn = ( typeof mobSpan!="undefined" && mobSpan!='' ? mobSpan : 'mobileCodeSpan' );
	var mID = ( typeof mobID!="undefined" && mobID!='' ? mobID : 'su_mobileCode' );
	var cCd = ( typeof ctyCode!="undefined" && ctyCode!='' ? ctyCode : 'su_cityCodeHomePhone' );	
	
	countrySelected=document.getElementById(fld).value;
	if(countrySelected=='Pakistan')
		getMobileCodes('width:53px;',mobID,mobSpan,ctCls);//function is in pkLocation.js
	else{
		document.getElementById(spn).innerHTML = '&nbsp;<input name="'+mID+'" type="text" id="'+mID+'"  value="'+mobVal+'" size="6" maxlength="6" class="'+ctCls+'"> &nbsp;';	
		document.getElementById(cCd).value='';	
	}
}


function triggerCityEvent(cntID,ctID,sp,f,cls,cdID){
	var cnt = ( typeof cntID!="undefined" && cntID!='' ? cntID : 'su_country' );
	var ct = ( typeof ctID!="undefined" && ctID!='' ? ctID : 'su_city' );
	var spn = ( typeof sp!="undefined" && sp!='' ? sp : 'su_cityCodeSpan' );
	var rf = ( typeof f!="undefined" && f!='' ? f : 'signup.php' );	
	var codID = ( typeof cdID!="undefined" && cdID!='' ? cdID : 'su_cityCodeHomePhone' );	
	ctCls = ( typeof cls!="undefined" && cls!='' ? cls:"" );	

	if(document.getElementById('su_country').value=='Pakistan')
		cityCode(cnt, ctID, spn, rf,codID,ctCls); 
}

function triggerPTCityEvent(cntID,ctID,sp,f,cls,cdID){
	var cnt = ( typeof cntID!="undefined" && cntID!='' ? cntID : 'pt_country' );
	var ct = ( typeof ctID!="undefined" && ctID!='' ? ctID : 'pt_city' );
	var spn = ( typeof sp!="undefined" && sp!='' ? sp : 'pt_CitiSpan' );
	var rf = ( typeof f!="undefined" && f!='' ? f : 'cp-personal-info.php' );	
	var codID = ( typeof cdID!="undefined" && cdID!='' ? cdID : 'pt_cityCodeHomePhone' );	
	ctCls = ( typeof cls!="undefined" && cls!='' ? cls:"" );	
 
	if(document.getElementById('pt_country').value=='Pakistan')
		cityCode(cnt, ctID, spn, rf,codID,ctCls); 
}

function cityCode_cb(new_data)
{		

	var str = new_data;	
	pstr = str.split(",");
	var rsSpan = pstr[0];
	var rsString = pstr[1];
	
	document.getElementById(rsSpan).innerHTML = rsString;
	enableDisable(globalField, false)	
	//document.getElementById(globalField).focus();
	return true;
}

function cityCode(countryField, cityCodeField, resultSpan, returnFile,cdID,ctCls)
{		
	var query = document.getElementById(countryField).value+"#"+document.getElementById(cityCodeField).value+"#"+cityCodeField+"#"+resultSpan+"#"+ctCls+'#'+cdID;
	document.getElementById(resultSpan).innerHTML = '<input name="" class="'+ctCls+'" type="text"  value="Wait..." size="6" maxlength="6" disabled>';
	//alert(cityField +" "+document.getElementById(countryField).value);
	//alert(resultSpan);
	globalField = cityCodeField;
	enableDisable(globalField, true);	
	cpaint_call (returnFile,'POST','cityCode',query, cityCode_cb);
	return false;
}


function getMobileCodes(css,fieldName,mobSpn,cls){

	var styl = ( typeof css!="undefined" && css!='' ? css : 'width: 63px;' );
	var fldName = ( typeof fieldName!="undefined" && fieldName!='' ? fieldName : 'su_mobileCode' );
	var clss = ( typeof cls!="undefined" && cls!='' ? cls : '' );	

	mobCodeCombo = '<select name="'+fldName+'" id="'+fldName+'" style="'+styl+'" class="'+clss+'"><option value="">Code</option><option value="300">300</option><option value="301">301</option><option value="302">302</option><option value="303">303</option><option value="304">304</option><option value="306">306</option><option value="307">307</option><option value="308">308</option><option value="312">312</option><option value="313">313</option><option value="314">314</option><option value="315">315</option><option value="320">320</option><option value="321">321</option><option value="322">322</option><option value="323">323</option><option value="331">331</option><option value="332">332</option><option value="333">333</option><option value="334">334</option><option value="343">343</option><option value="344">344</option><option value="345">345</option><option value="346">346</option></select> ';
	var mSpan = ( typeof mobSpn!="undefined" && mobSpn!='' ? mobSpn : 'mobileCodeSpan' );
	document.getElementById(mSpan).innerHTML = mobCodeCombo;   	
}