jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function setPaging(form,currPage,numberOfRecordsPerPage){
   document.getElementById('resetPaging').value='N';
   document.getElementById('currPage').value=currPage;
   document.getElementById('numberOfRecordsPerPage').value=numberOfRecordsPerPage;
   asynchronousProcessByPost(form); 
}
function setPagingGroup(form,currPageGroup,numberOfRecordsPerPage){
   document.getElementById('resetPaging').value='N';
   document.getElementById('currPageGroup').value=currPageGroup;
   document.getElementById('currPage').value=(currPageGroup-1)*10+1;
   document.getElementById('numberOfRecordsPerPage').value=numberOfRecordsPerPage;
   asynchronousProcessByPost(form);
}
function setRecords(form,value){
   document.getElementById('resetPaging').value='N';
   document.getElementById('numberOfRecordsPerPage').value=value;
   asynchronousProcessByPost(form);
}

//function to check integer values
function checkInt(text){

		var chk= "0123456789";
		var lent,flag= false;
		 lent = text;
		var ans;
		for(i=0;i<lent.length;i++){
			
			for(j=0;j<chk.length;j++){
			
				if(lent.charAt(i) == chk.charAt(j)){
					if(ans == 1){
						break;
					}
					flag=true;
					ans = 0;				
					break;

				}
				else{
				
					if(j == chk.length - 1){
						ans = 1;
						break;
					}
				}
					
				
			}
			
		}
	
		if(ans == 0){
			return true;
		}else{
			
			return false;
		}
		
}
//function to check valid email address
function isValidEmail(strEmail)
{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) 
	{
		return false;	
	}
	return true; 
}

function ltrim(argvalue) 
{
	while (1)
	{
		if (argvalue.substring(0, 1) != " ")
		break;
		argvalue = argvalue.substring(1, argvalue.length);
	}	
	return argvalue;
}

function rtrim(argvalue) 
{

	while (1) 
	{
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	
	return argvalue;
}

function trim(argvalue)
{
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

function isURL(argvalue) 
{

	if (argvalue.indexOf(" ") != -1)
		return false;
	else if (argvalue.indexOf("http://") == -1)
		return false;
	else if (argvalue == "http://")
		return false;
	else if (argvalue.indexOf("http://") > 0)
		return false;

	argvalue = argvalue.substring(7, argvalue.length);
	if (argvalue.indexOf(".") == -1)
		return false;
	else if (argvalue.indexOf(".") == 0)
		return false;
	else if (argvalue.charAt(argvalue.length - 1) == ".")
		return false;
	
	if (argvalue.indexOf("/") != -1)
	{
		argvalue = argvalue.substring(0, argvalue.indexOf("/"));
		if (argvalue.charAt(argvalue.length - 1) == ".")
		return false;
	}
	
	if (argvalue.indexOf(":") != -1) 
	{
		if (argvalue.indexOf(":") == (argvalue.length - 1))
			return false;
		else if (argvalue.charAt(argvalue.indexOf(":") + 1) == ".")
			return false;
		argvalue = argvalue.substring(0, argvalue.indexOf(":"));
		if (argvalue.charAt(argvalue.length - 1) == ".")
			return false;
	}
	
	return true;

}

function isURL(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@\,\!\-\/]))?/
	//var regexp = /(ftp|http|https):\/\/(\w{0,2}\w*)?(\S+)([0-9]+)?(.)?(S+)/
	/*//var regexp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}[0-9A-Za-z\.\-]*\.[0-9A-Za-z\.\-]*$/
	//var regexp = /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/
	var regexp = (((http?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i*/
	return regexp.test(s);
}
function validateName(name,fieldname)
{
	var iChars = "`~!@#$%^&*()+=-[]\\\';,/{}|\":<>?";
	for (var i = 0; i < name.length; i++) 
	{
		if (iChars.indexOf(name.charAt(i)) != -1) 
		{
			alert ("special characters are not allowed in " + fieldname + ".");
			return false;
		}
	}
	return true;
}

// Password Validator
function isPass(pass1,pass2)	
{
	if ((pass1 == "") || (pass1.length < 6))
	{
		alert("\nThe password field is either empty or less than 6 chars.\n\nPlease enter your password.")
		return false;
	}
	if (pass1 != pass2)
	{
		alert("Passwords typed do not match, please re-enter your passwords.\n\n");
		return false;
	}
	return true;
}

function isDate(mm,dd,yyyy) 
{
	var d = new Date(mm + "/" + dd + "/" + yyyy);
	return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}


function in_array(needle, haystack) 
{
	var n = haystack.length;
	for(var i=0; i<n; i++) 
	{
		if (haystack[i]==needle.toLowerCase()) 
		{
			return true;
		}
	}
	return false;
}

function goToURL()
{
	var loopInitialValue = 0;
	var url = "index.php?";
	if (arguments[0] == 0)
	{
		url += "module="+arguments[1]+"&task="+arguments[2];
	}
	else if (arguments[0] == 1)
	{
		url += "module="+arguments[1]+"&task="+arguments[2]+"&";
		loopInitialValue = 3;
		for(var i=loopInitialValue; i<arguments.length; i+=2)
		{
			url += arguments[i]+"="+arguments[i+1]+"&";
		}
		url = url.substring(0, url.length-1);
	}
	window.location.href = url;
}

function showPopUp(url)
{	
	var intSrcWidth  = screen.width;
	var intSrcHeight = screen.height;
	window.open(url,'','"width='+intSrcWidth+',height='+intSrcHeight+',channelmode=yes,resizable=yes,scrollbars=yes,left=0,top=0"');
}
function getDetailsByAjax(module,task,param,Id,divId)
{
	ajaxManager("start_up","index.php?module="+module+"&task="+task+"&"+param+"="+Id,divId);
}

function showPopUpWin(url)
{	
	window.open(url,'','"width=400,height=600,channelmode=yes,resizable=yes,scrollbars=yes,left=0,top=0"');
} 
function showMsgDiv(msg,did)
{  
	document.getElementById(did+"_alert").innerHTML=msg;
	document.getElementById(did+"_alert").style.display='block';
	$j("#"+did+"_alert").fadeOut(500).fadeIn(500);   
}
function showMsgAlert(msg)
{   
	 
	 $j.twittadbox(msg);
	 
}

function showImageTB(img,c)
{   

	 $j.twittadbox({image:img},c);
	 	 
}

function clearValidationAlert(arr)
{   
	if(arr.length>0)
	{
		for(i=0;i<arr.length;i++)
		{  
			if(document.getElementById(arr[i]))
			{
				$j("#"+arr[i]+"_alert").fadeOut(500).fadeIn(500);  
				document.getElementById(arr[i]+"_alert").innerHTML='';
				document.getElementById(arr[i]+"_alert").style.display='block'; 
				document.getElementById(arr[i]+"_alert").style.display='none'; 				
			}
		}
	} 
}
function openAjaxInBox(url)
{   
	$j.twittadbox ({ajax:url}); 
	
}

function confirmMessage(title,content,url){ 
 
 $j.twittadbox(function(){  
			 jConfirm(content, title,  
				function(r) { 
					if(r==true)
					{
						 window.location.href = url;
					}  
		    });  
	 });
	 
}
function confirmDelete(title,content,frmobj,actionval){ 
 
 $j.twittadbox(function(){  
			 jConfirm(content, title,  
				function(r) { 
					if(r==true)
					{
						frmobj.action.value = actionval;
						frmobj.submit();
					}  
		    });  
	 });
	 
}

function confirmURL(title,content,url){ 
 
 $j.twittadbox(function(){  
			 jConfirm(content, title,  
				function(r) { 
					if(r==true)
					{
						window.location.href=url
					}  
		    });  
	 });
	 
} 




function confirmJS(title,content,jsFunction){ 
	var result = false;
 	$j.twittadbox(function(){  
		var jr =   jConfirm(content, title,  
			function(r) { 
			if(r==true)
			{
				eval(jsFunction+'();');
			}  
		});  
		
	 });
} 

function accordianLeftMenu(identiFiers_h,identiFiers_c,element) {  
  var COOKIE_NAME = 'leftmenuactiveid'; 
  var options = { path: '/', expires: 2 };

  $j(identiFiers_h).hide();   
  
    if($j.cookie(COOKIE_NAME)!='')
	{   
	   $j(identiFiers_h+'#'+$j.cookie(COOKIE_NAME)).css('display', 'block'); 
	   $j(identiFiers_h+'#'+$j.cookie(COOKIE_NAME)+'_m').addClass('active');  
	} 
  $j(identiFiers_c).click(
    function() {  
	 
	  var cookieValue = $j(this).next().attr('id');  
	  $j.cookie(COOKIE_NAME, cookieValue, options);  
      var checkElement = $j(this).next();
	  
      if((checkElement.is(element)) && (checkElement.is(':visible'))) {
		 
		  $j(this).next().slideToggle();
          return false;
        }
      if((checkElement.is(element)) && (!checkElement.is(':visible'))) { 
		   
          $j(identiFiers_h+':visible').slideUp('normal'); 
          checkElement.slideDown('normal'); 
		  $j('#'+$j.cookie(COOKIE_NAME)+'_m').addClass('active'); 
		  $j('#'+$j.cookie(COOKIE_NAME)+'_m').siblings().removeClass('active'); 
          return false;
        }
		
      }
    );
  
  }
 
 
 function accordianLeftInnerMenu(identiFiers_h,identiFiers_c,element) {  
   
  $j(identiFiers_c).click(
    function() {   
	   
      var checkElement = $j(this).next();
	  
      if((checkElement.is(element)) && (checkElement.is(':visible'))) {
		 
		  $j(this).next().slideToggle();
          return false;
        }
      if((checkElement.is(element)) && (!checkElement.is(':visible'))) { 
		   
          $j(identiFiers_h+':visible').slideUp('normal'); 
          checkElement.slideDown('normal'); 
		   
          return false;
        }
		
      }
    );
  
  }
 
 
function tabHighLight(mcn,acn,type){  
$j(type+mcn+' ul li').click(function(event) {
		  $j(this).addClass(acn).siblings().removeClass(acn); 
	 }); 
}
function leftSideSlider(id1,id2)
{   
 	$j('#'+$j.cookie('leftmenuactiveid')+'_m').addClass('active') ;  
	$j('#'+$j.cookie('leftmenuactiveid')+'_m').siblings().removeClass('active') ;  
	$j("#"+id2).fadeOut(500).fadeIn(500).slideDown("fast");  
	document.getElementById(id1).style.display = "none";   
	$j("#"+id1).slideUp("fast");   
	document.getElementById(id2).style.display = "block"; 
}
function openSubMenu(url,id) 
{  	  
	$j.cookie('menuactiveid', id, { path: '/', expires:1 });  
	window.location.href=url
}
function activateMenu()
{  
	if(!$j.cookie('menuactiveid')){  
		 //$j('#leftMenuForPI ul li').attr('id').addClass('active'); 
		 if($j('#leftMenuForPI ul li').attr('id'))
		 {
			 $j('#leftMenuForPI ul li').addClass('active');  
		 }
		// $j('#leftMenuForPI ul li ul li').removeClass('active'); 
		 $j('#leftMenuForPI').html($j('#leftMenuForPI').html()); 
		 $j('#leftMenuForPI ul li ul').show(); 
	}
	else
	{ 
	    $j('#leftMenuForPI').html('<ul><li class="active">'+$j('#'+$j.cookie('menuactiveid')).html()+'</li></ul>');   
		$j('#leftMenuForPI ul li ul').show(); 
	}
	 
//	$j('#leftMenuForPI ul li ul').hide(); 
	
	$j('#leftMenuForPI ul li h4').click(
			function() { 
				
				var checkElement = $j(this).next(); 
				$j(this).addClass('activeArrow');
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					$j(this).next().slideToggle();
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$j('#leftMenuForPI ul li ul:visible').slideUp('normal');
					checkElement.slideDown('normal');
					return false;
				}
				
			}
		);
	
}



function showDiv(divId, action)
{

	if(action=='s')
	{	$j('#'+divId).fadeIn(500); 
		document.getElementById(divId).style.display="block";
		
	}
	else if(action=='h')
	{	$j('#'+divId).fadeOut(500); 
		document.getElementById(divId).style.display="none"; 
	}
	tabHighLight('rectTabs','active','.'); 
}




 
    //--------------COUNTRY STATE FORMS---added by pks 6th April 2010----------------------------------------------
    // State table
    //
    // To edit the list, just delete a line or add a line. Order is important.
    // The order displayed here is the order it appears on the drop down.
    //
    var state = '\
        United States:AK:Alaska|\
        United States:AL:Alabama|\
        United States:AR:Arkansas|\
        United States:AS:American Samoa|\
        United States:AZ:Arizona|\
        United States:CA:California|\
        United States:CO:Colorado|\
        United States:CT:Connecticut|\
        United States:DC:D.C.|\
        United States:DE:Delaware|\
        United States:FL:Florida|\
        United States:FM:Micronesia|\
        United States:GA:Georgia|\
        United States:GU:Guam|\
        United States:HI:Hawaii|\
        United States:IA:Iowa|\
        United States:ID:Idaho|\
        United States:IL:Illinois|\
        United States:IN:Indiana|\
        United States:KS:Kansas|\
        United States:KY:Kentucky|\
        United States:LA:Louisiana|\
        United States:MA:MassachUnited Statesetts|\
        United States:MD:Maryland|\
        United States:ME:Maine|\
        United States:MH:Marshall Islands|\
        United States:MI:Michigan|\
        United States:MN:Minnesota|\
        United States:MO:Missouri|\
        United States:MP:Marianas|\
        United States:MS:Mississippi|\
        United States:MT:Montana|\
        United States:NC:North Carolina|\
        United States:ND:North Dakota|\
        United States:NE:Nebraska|\
        United States:NH:New Hampshire|\
        United States:NJ:New Jersey|\
        United States:NM:New Mexico|\
        United States:NV:Nevada|\
        United States:NY:New York|\
        United States:OH:Ohio|\
        United States:OK:Oklahoma|\
        United States:OR:Oregon|\
        United States:PA:Pennsylvania|\
        United States:PR:Puerto Rico|\
        United States:PW:Palau|\
        United States:RI:Rhode Island|\
        United States:SC:South Carolina|\
        United States:SD:South Dakota|\
        United States:TN:Tennessee|\
        United States:TX:Texas|\
        United States:UT:Utah|\
        United States:VA:Virginia|\
        United States:VI:Virgin Islands|\
        United States:VT:Vermont|\
        United States:WA:Washington|\
        United States:WI:Wisconsin|\
        United States:WV:West Virginia|\
        United States:WY:Wyoming|\
        United States:AA:Military Americas|\
        United States:AE:Military Europe/ME/Canada|\
        United States:AP:Military Pacific|\
        CA:AB:Alberta|\
	    CA:MB:Manitoba|\
	    CA:AB:Alberta|\
	    CA:BC:British Columbia|\
	    CA:MB:Manitoba|\
	    CA:NB:New Brunswick|\
	    CA:NL:Newfoundland and Labrador|\
	    CA:NS:Nova Scotia|\
	    CA:NT:Northwest Territories|\
	    CA:NU:Nunavut|\
	    CA:ON:Ontario|\
	    CA:PE:Prince Edward Island|\
	    CA:QC:Quebec|\
	    CA:SK:Saskatchewan|\
	    CA:YT:Yukon Territory|\
	    AU:AAT:Australian Antarctic Territory|\
	    AU:ACT:Australian Capital Territory|\
	    AU:NT:Northern Territory|\
	    AU:NSW:New South Wales|\
	    AU:QLD:Queensland|\
	    AU:SA:South Australia|\
	    AU:TAS:Tasmania|\
	    AU:VIC:Victoria|\
	    AU:WA:Western Australia|\
	    BR:AC:Acre|\
	    BR:AL:Alagoas|\
	    BR:AM:Amazonas|\
	    BR:AP:Amapa|\
	    BR:BA:Baia|\
	    BR:CE:Ceara|\
	    BR:DF:Distrito Federal|\
	    BR:ES:Espirito Santo|\
	    BR:FN:Fernando de Noronha|\
	    BR:GO:Goias|\
	    BR:MA:Maranhao|\
	    BR:MG:Minas Gerais|\
	    BR:MS:Mato Grosso do Sul|\
	    BR:MT:Mato Grosso|\
	    BR:PA:Para|\
	    BR:PB:Paraiba|\
	    BR:PE:Pernambuco|\
	    BR:PI:Piaui|\
	    BR:PR:Parana|\
	    BR:RJ:Rio de Janeiro|\
	    BR:RN:Rio Grande do Norte|\
	    BR:RO:Rondonia|\
	    BR:RR:Roraima|\
	    BR:RS:Rio Grande do Sul|\
	    BR:SC:Santa Catarina|\
	    BR:SE:Sergipe|\
	    BR:SP:Sao Paulo|\
	    BR:TO:Tocatins|\
	    NL:DR:Drente|\
	    NL:FL:Flevoland|\
	    NL:FR:Friesland|\
	    NL:GL:Gelderland|\
	    NL:GR:Groningen|\
	    NL:LB:Limburg|\
	    NL:NB:Noord Brabant|\
	    NL:NH:Noord Holland|\
	    NL:OV:Overijssel|\
	    NL:UT:Utrecht|\
	    NL:ZH:Zuid Holland|\
	    NL:ZL:Zeeland|\
	    UK:AVON:Avon|\
	    UK:BEDS:Bedfordshire|\
	    UK:BERKS:Berkshire|\
	    UK:BUCKS:Buckinghamshire|\
	    UK:CAMBS:Cambridgeshire|\
	    UK:CHESH:Cheshire|\
	    UK:CLEVE:Cleveland|\
	    UK:CORN:Cornwall|\
	    UK:CUMB:Cumbria|\
	    UK:DERBY:Derbyshire|\
	    UK:DEVON:Devon|\
	    UK:DORSET:Dorset|\
	    UK:DURHAM:Durham|\
	    UK:ESSEX:Essex|\
	    UK:GLOUS:Gloucestershire|\
	    UK:GLONDON:Greater London|\
	    UK:GMANCH:Greater Manchester|\
	    UK:HANTS:Hampshire|\
	    UK:HERWOR:Hereford & Worcestershire|\
	    UK:HERTS:Hertfordshire|\
	    UK:HUMBER:Humberside|\
	    UK:IOM:Isle of Man|\
	    UK:IOW:Isle of Wight|\
	    UK:KENT:Kent|\
	    UK:LANCS:Lancashire|\
	    UK:LEICS:Leicestershire|\
	    UK:LINCS:Lincolnshire|\
	    UK:MERSEY:Merseyside|\
	    UK:NORF:Norfolk|\
	    UK:NHANTS:Northamptonshire|\
	    UK:NTHUMB:Northumberland|\
	    UK:NOTTS:Nottinghamshire|\
	    UK:OXON:Oxfordshire|\
	    UK:SHROPS:Shropshire|\
	    UK:SOM:Somerset|\
	    UK:STAFFS:Staffordshire|\
	    UK:SUFF:Suffolk|\
	    UK:SURREY:Surrey|\
	    UK:SUSS:Sussex|\
	    UK:WARKS:Warwickshire|\
	    UK:WMID:West Midlands|\
	    UK:WILTS:Wiltshire|\
	    UK:YORK:Yorkshire|\
	    EI:CO ANTRIM:County Antrim|\
	    EI:CO ARMAGH:County Armagh|\
	    EI:CO DOWN:County Down|\
	    EI:CO FERMANAGH:County Fermanagh|\
	    EI:CO DERRY:County Londonderry|\
	    EI:CO TYRONE:County Tyrone|\
	    EI:CO CAVAN:County Cavan|\
	    EI:CO DONEGAL:County Donegal|\
	    EI:CO MONAGHAN:County Monaghan|\
	    EI:CO DUBLIN:County Dublin|\
	    EI:CO CARLOW:County Carlow|\
	    EI:CO KILDARE:County Kildare|\
	    EI:CO KILKENNY:County Kilkenny|\
	    EI:CO LAOIS:County Laois|\
	    EI:CO LONGFORD:County Longford|\
	    EI:CO LOUTH:County Louth|\
	    EI:CO MEATH:County Meath|\
	    EI:CO OFFALY:County Offaly|\
	    EI:CO WESTMEATH:County Westmeath|\
	    EI:CO WEXFORD:County Wexford|\
	    EI:CO WICKLOW:County Wicklow|\
	    EI:CO GALWAY:County Galway|\
	    EI:CO MAYO:County Mayo|\
	    EI:CO LEITRIM:County Leitrim|\
	    EI:CO ROSCOMMON:County Roscommon|\
	    EI:CO SLIGO:County Sligo|\
	    EI:CO CLARE:County Clare|\
	    EI:CO CORK:County Cork|\
	    EI:CO KERRY:County Kerry|\
	    EI:CO LIMERICK:County Limerick|\
	    EI:CO TIPPERARY:County Tipperary|\
	    EI:CO WATERFORD:County Waterford|\
	    ';

    // Country data table
    //
    // To edit the list, just delete a line or add a line. Order is important.
    // The order displayed here is the order it appears on the drop down.
    //
    var country = '\
    AF:Afghanistan|\
    AL:Albania|\
    DZ:Algeria|\
    AS:American Samoa|\
    AD:Andorra|\
    AO:Angola|\
    AI:Anguilla|\
    AQ:Antarctica|\
    AG:Antigua and Barbuda|\
    AR:Argentina|\
    AM:Armenia|\
    AW:Aruba|\
    AU:Australia|\
    AT:Austria|\
    AZ:Azerbaijan|\
    AP:Azores|\
    BS:Bahamas|\
    BH:Bahrain|\
    BD:Bangladesh|\
    BB:Barbados|\
    BY:Belarus|\
    BE:Belgium|\
    BZ:Belize|\
    BJ:Benin|\
    BM:Bermuda|\
    BT:Bhutan|\
    BO:Bolivia|\
    BA:Bosnia And Herzegowina|\
    XB:Bosnia-Herzegovina|\
    BW:Botswana|\
    BV:Bouvet Island|\
    BR:Brazil|\
    IO:British Indian Ocean Territory|\
    VG:British Virgin Islands|\
    BN:Brunei Darussalam|\
    BG:Bulgaria|\
    BF:Burkina Faso|\
    BI:Burundi|\
    KH:Cambodia|\
    CM:Cameroon|\
    CA:Canada|\
    CV:Cape Verde|\
    KY:Cayman Islands|\
    CF:Central African Republic|\
    TD:Chad|\
    CL:Chile|\
    CN:China|\
    CX:Christmas Island|\
    CC:Cocos (Keeling) Islands|\
    CO:Colombia|\
    KM:Comoros|\
    CG:Congo|\
    CD:Congo, The Democratic Republic O|\
    CK:Cook Islands|\
    XE:Corsica|\
    CR:Costa Rica|\
    CI:Cote d` Ivoire (Ivory Coast)|\
    HR:Croatia|\
    CU:Cuba|\
    CY:Cyprus|\
    CZ:Czech Republic|\
    DK:Denmark|\
    DJ:Djibouti|\
    DM:Dominica|\
    DO:Dominican Republic|\
    TP:East Timor|\
    EC:Ecuador|\
    EG:Egypt|\
    SV:El Salvador|\
    GQ:Equatorial Guinea|\
    ER:Eritrea|\
    EE:Estonia|\
    ET:Ethiopia|\
    FK:Falkland Islands (Malvinas)|\
    FO:Faroe Islands|\
    FJ:Fiji|\
    FI:Finland|\
    FR:France (Includes Monaco)|\
    FX:France, Metropolitan|\
    GF:French Guiana|\
    PF:French Polynesia|\
    TA:French Polynesia (Tahiti)|\
    TF:French Southern Territories|\
    GA:Gabon|\
    GM:Gambia|\
    GE:Georgia|\
    DE:Germany|\
    GH:Ghana|\
    GI:Gibraltar|\
    GR:Greece|\
    GL:Greenland|\
    GD:Grenada|\
    GP:Guadeloupe|\
    GU:Guam|\
    GT:Guatemala|\
    GN:Guinea|\
    GW:Guinea-Bissau|\
    GY:Guyana|\
    HT:Haiti|\
    HM:Heard And Mc Donald Islands|\
    VA:Holy See (Vatican City State)|\
    HN:Honduras|\
    HK:Hong Kong|\
    HU:Hungary|\
    IS:Iceland|\
    IN:India|\
    ID:Indonesia|\
    IR:Iran|\
    IQ:Iraq|\
    IE:Ireland|\
    EI:Ireland (Eire)|\
    IL:Israel|\
    IT:Italy|\
    JM:Jamaica|\
    JP:Japan|\
    JO:Jordan|\
    KZ:Kazakhstan|\
    KE:Kenya|\
    KI:Kiribati|\
    KP:Korea, Democratic People\'S Repub|\
    KW:Kuwait|\
    KG:Kyrgyzstan|\
    LA:Laos|\
    LV:Latvia|\
    LB:Lebanon|\
    LS:Lesotho|\
    LR:Liberia|\
    LY:Libya|\
    LI:Liechtenstein|\
    LT:Lithuania|\
    LU:Luxembourg|\
    MO:Macao|\
    MK:Macedonia|\
    MG:Madagascar|\
    ME:Madeira Islands|\
    MW:Malawi|\
    MY:Malaysia|\
    MV:Maldives|\
    ML:Mali|\
    MT:Malta|\
    MH:Marshall Islands|\
    MQ:Martinique|\
    MR:Mauritania|\
    MU:Mauritius|\
    YT:Mayotte|\
    MX:Mexico|\
    FM:Micronesia, Federated States Of|\
    MD:Moldova, Republic Of|\
    MC:Monaco|\
    MN:Mongolia|\
    MS:Montserrat|\
    MA:Morocco|\
    MZ:Mozambique|\
    MM:Myanmar (Burma)|\
    NA:Namibia|\
    NR:Nauru|\
    NP:Nepal|\
    NL:Netherlands|\
    AN:Netherlands Antilles|\
    NC:New Caledonia|\
    NZ:New Zealand|\
    NI:Nicaragua|\
    NE:Niger|\
    NG:Nigeria|\
    NU:Niue|\
    NF:Norfolk Island|\
    MP:Northern Mariana Islands|\
    NO:Norway|\
    OM:Oman|\
    PK:Pakistan|\
    PW:Palau|\
    PS:Palestinian Territory, Occupied|\
    PA:Panama|\
    PG:Papua New Guinea|\
    PY:Paraguay|\
    PE:Peru|\
    PH:Philippines|\
    PN:Pitcairn|\
    PL:Poland|\
    PT:Portugal|\
    PR:Puerto Rico|\
    QA:Qatar|\
    RE:Reunion|\
    RO:Romania|\
    RU:Russian Federation|\
    RW:Rwanda|\
    KN:Saint Kitts And Nevis|\
    SM:San Marino|\
    ST:Sao Tome and Principe|\
    SA:Saudi Arabia|\
    SN:Senegal|\
    XS:Serbia-Montenegro|\
    SC:Seychelles|\
    SL:Sierra Leone|\
    SG:Singapore|\
    SK:Slovak Republic|\
    SI:Slovenia|\
    SB:Solomon Islands|\
    SO:Somalia|\
    ZA:South Africa|\
    GS:South Georgia And The South Sand|\
    KR:South Korea|\
    ES:Spain|\
    LK:Sri Lanka|\
    NV:St. Christopher and Nevis|\
    SH:St. Helena|\
    LC:St. Lucia|\
    PM:St. Pierre and Miquelon|\
    VC:St. Vincent and the Grenadines|\
    SD:Sudan|\
    SR:Suriname|\
    SJ:Svalbard And Jan Mayen Islands|\
    SZ:Swaziland|\
    SE:Sweden|\
    CH:Switzerland|\
    SY:Syrian Arab Republic|\
    TW:Taiwan|\
    TJ:Tajikistan|\
    TZ:Tanzania|\
    TH:Thailand|\
    TG:Togo|\
    TK:Tokelau|\
    TO:Tonga|\
    TT:Trinidad and Tobago|\
    XU:Tristan da Cunha|\
    TN:Tunisia|\
    TR:Turkey|\
    TM:Turkmenistan|\
    TC:Turks and Caicos Islands|\
    TV:Tuvalu|\
    UG:Uganda|\
    UA:Ukraine|\
    AE:United Arab Emirates|\
    UK:United Kingdom|\
    GB:Great Britain|\
    United States:United States|\
    UM:United States Minor Outlying Isl|\
    UY:Uruguay|\
    UZ:Uzbekistan|\
    VU:Vanuatu|\
    XV:Vatican City|\
    VE:Venezuela|\
    VN:Vietnam|\
    VI:Virgin Islands (U.S.)|\
    WF:Wallis and Furuna Islands|\
    EH:Western Sahara|\
    WS:Western Samoa|\
    YE:Yemen|\
    YU:Yugoslavia|\
    ZR:Zaire|\
    ZM:Zambia|\
    ZW:Zimbabwe|\
    ';
 
     
    var countryId ='';
    var stateId = '';
    var stateNm = '';
    
    
    
    function TrimString(sInString) {
      if ( sInString ) {
        sInString = sInString.replace( /^\s+/g, "" );// strip leading
        return sInString.replace( /\s+$/g, "" );// strip trailing
      }
    }

    // Populates the country selected with the counties from the country list
    function populateCountry(defaultCountry,countryId) {

      var countryLineArray = country.split('|');  // Split into lines
      var selObj = document.getElementById(countryId);
      selObj.options[0] = new Option('Select Country','');
      selObj.selectedIndex = 0;
      for (var loop = 0; loop < countryLineArray.length; loop++) {
        lineArray = countryLineArray[loop].split(':');
        countryCode  = TrimString(lineArray[0]);
        countryName  = TrimString(lineArray[1]);
        if ( countryCode != '' ) {
          selObj.options[loop + 1] = new Option(countryName, countryName);
        }
        if ( defaultCountry == countryName ) {
          selObj.selectedIndex = loop + 1;
        }
      }
    }

    function populateState(stateVal,countryVal,stateId,stateNm,countryId) {
   		
      var selObj = document.getElementById(stateId);
      
      var foundState = false;
      // Empty options just in case new drop down is shorter
      if ( selObj.type == 'select-one' ) {
        for (var i = 0; i < selObj.options.length; i++) {
          selObj.options[i] = null;
        }
        selObj.options.length=null;
        selObj.options[0] = new Option('Select State','');
        selObj.selectedIndex = 0;
      }
      // Populate the drop down with states from the selected country
      var stateLineArray = state.split("|");  // Split into lines
      var optionCntr = 1;
//      alert(document.getElementById(countryId).value);
//		alert(stateVal);
//		alert(countryVal);
		
      for (var loop = 0; loop < stateLineArray.length; loop++) {
        lineArray = stateLineArray[loop].split(":");
        countryCode  = TrimString(lineArray[0]);
        stateCode    = TrimString(lineArray[1]);
        stateName    = TrimString(lineArray[2]);
        
        
		
        
      if (document.getElementById(countryId).value == countryCode && countryCode != '' ) {
        // If it's a input element, change it to a select
           if ( selObj.type == 'text' ) {
            parentObj = document.getElementById(stateId).parentNode;
            parentObj.removeChild(selObj);
            var inputSel = document.createElement("SELECT");
			inputSel.setAttribute("name",stateNm);
			
            inputSel.setAttribute("id",stateId);
			parentObj.appendChild(inputSel) ;
			 
            selObj = document.getElementById(stateId);
			selObj.options[0] = new Option('Select State','');
            //selObj.selectedIndex = 0;
			
			if ( stateVal == stateName ) {
				alert("stateVal ==");
                selObj.selectedIndex = loop + 1;
			}
			
          }
          if ( stateCode != '' ) {
			  //alert("stateCode !=");
          
            selObj.options[optionCntr] = new Option(stateName, stateName);
          }
          // See if it's selected from a previous post
     //     if(loop < 4)
//		  alert(stateName+" & "+stateVal+" & "+countryCode+" & "+countryVal);
		  if ( (stateName == stateVal) && (countryCode == countryVal) ) {
//			  alert("stateCode == stateVal && countryCode == countryVal");
              selObj.selectedIndex = optionCntr;
          }
          foundState = true;
          optionCntr++
        }
      }
      //alert(foundState);
	  //alert(selObj.selectedIndex);
	  // If the country has no states, change the select to a text box
      if ( ! foundState ) {
		  //alert("! foundState");
        parentObj = document.getElementById(stateId).parentNode;
        parentObj.removeChild(selObj);
      // Create the Input Field
        var inputEl = document.createElement("INPUT");
        inputEl.setAttribute("name", stateNm);
        inputEl.setAttribute("id", stateId);
        inputEl.setAttribute("type", "text");
        inputEl.setAttribute("value", stateVal);
        inputEl.setAttribute("class", "textBoxG");//class="textBoxG"
        parentObj.appendChild(inputEl) ;
      }
    }

    function initCountry(countryVal,stateVal,countryId, stateId, stateNm) {
    	populateCountry(countryVal,countryId);
    	populateState(stateVal,countryVal,stateId,stateNm,countryId);
    }

    
    
//----------------added by pks 6th April 2010---------------------------------------------------------------------

