// Javascript File //
/* Validations on the Profile Page "Mail Sending" and "Text Messaging" Send Buttons. */

/* This Function is called on the "Page Body Load" */

function mychangefunction()
{
    window.status = '';
    return true;
}

function getIEVersionNumber() 
{
    try
    {
        var ua = navigator.userAgent;
        var MSIEOffset = ua.indexOf("MSIE ");

        if (MSIEOffset == -1) {
            return 0;
        } else {
            return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
        }
     }
     catch(ex)
     {}   
}

function Fill()
{
/* Code for Search Result Problem */

//if(document.getElementById("cse-search-box"))
//{	
//	document.getElementById("cse-search-box").setAttribute('action', '');
//	document.getElementById("button").style.cursor="default";
//	var browserVer=parseInt(navigator.appVersion); 
//	try
//    {
//        if(document.all)
//        {
//            if (parseInt(getIEVersionNumber()) > 7)
//            {
//                  document.getElementById("button").setAttribute('onmouseover', 'window.status="";return true;');
//            }
//            else
//            { 
//                  document.getElementById("button").setAttribute('onmouseover', mychangefunction);
//            }
//        }    
//        else
//        {
//             document.getElementById("button").setAttribute('onmouseover', mychangefunction);
//        }
//    }
//    catch(ex)
//     {
//           document.getElementById("button").setAttribute('onmouseover', 'window.status="";return true;');
//     }  
//}

/* END code */

    var pageflag=0;
	var fullURL = parent.document.URL;
	var strKey = "";
	var strK = "";
	if(fullURL.indexOf('&r=')>-1)
	{
		var stIndex = fullURL.indexOf('&r=');
		var endIndex = 0;
		for(var m=stIndex+3; m<fullURL.length; m++)
		{
			if(fullURL.charAt(m) == '&')
			{
				endIndex = m;
				break;
			}
		}
		if(endIndex != 0)
		{
			strKey = fullURL.substring(stIndex + 3, endIndex);
		}
		if(strKey != "")
		{
			var key = "";
			for(var n=0;n<strKey.length;n++)
			{
				strKey = strKey.replace('+',' ');
			}
			for(var n=0;n<strKey.length;n++)
			{
                strKey = strKey.replace('%2528','(');      
				strKey = strKey.replace('%2B','+');
				strKey = strKey.replace('%2C',',');
				strKey = strKey.replace('%3B',';');
				strKey = strKey.replace('%3D','=');
				strKey = strKey.replace('%2F','/');
				strKey = strKey.replace('%3F','?');
				strKey = strKey.replace('%3A',':');
				strKey = strKey.replace('%26','&');
				strKey = strKey.replace('%27',"'");
				strKey = strKey.replace('%28','(');
                strKey = strKey.replace('%23','#');   
				strKey = strKey.replace('%29',')');
              strKey = strKey.replace('%22','"');
				strKey = strKey.replace('%2527',"'");   
				strKey = strKey.replace('%2529',')');
			}
			document.getElementById("r").value = strKey;
		}
		if(fullURL.indexOf('&p=')>-1)
		{
			var stIndex = fullURL.indexOf('&p=');
			var endIndex = 0;
			for(var m=stIndex+3; m<fullURL.length; m++)
			{
				if(fullURL.charAt(m) == '&')
				{
					endIndex = m;
					break;
				}
			}
			if(endIndex != 0)
			{
				strK = fullURL.substring(stIndex + 3, endIndex);
			}
			if(strK != "")
			{
				if(strK.indexOf('+in+')>-1)
				{
					strK = strK.substring(0,strK.indexOf('+in+'));
				}
				var key = "";
				for(var n=0;n<strK.length;n++)
				{
					strK = strK.replace('+',' ');
				}
				for(var n=0;n<strK.length;n++)
				{
                    strK = strK.replace('%2528','(');        
					strK = strK.replace('%2B','+');	
					strK = strK.replace('%2B','+');
					strK  = strK.replace('%2C',',');
					strK = strK.replace('%3B',';');
					strK = strK.replace('%3D','=');
					strK = strK.replace('%2F','/');
					strK = strK.replace('%3F','?');
					strK = strK.replace('%3A',':');
					strK = strK.replace('%26','&');
					strK = strK.replace('%27',"'");
					strK = strK.replace('%28','(');
					strK = strK.replace('%29',')');
                    strK = strK.replace('%22','"');
                    strK = strK.replace('%23','#');    

                    strK = strK.replace('%2527',"'");   
				    strK = strK.replace('%2529',')');
				}
				document.getElementById("p").value = strK;
			}
		}
	}
	else if(fullURL.indexOf('&q=')>-1)
	{
		try
		{
			var stIndex = fullURL.indexOf('&q=');
			var endIndex = 0;
			for(var m=stIndex+3; m<fullURL.length; m++)
			{
				if(fullURL.charAt(m) == '#')
				{
					endIndex = m; 
					break;
				}
				else if(fullURL.charAt(m) == '&')
				{
					endIndex = m; 
					break;
				}
			}

			if(endIndex != 0)
			{
				strKey = fullURL.substring(stIndex + 3, endIndex);
			}
			if(strKey != '')
			{
				var key = '';
				for(var n=0;n<strKey.length;n++)
				{
					strKey = strKey.replace('+',' ');
					strKey = strKey.replace('%20',' ');
					strKey = strKey.replace('%27',"'");
				}
				for(var n=0;n<strKey.length;n++)
				{
                    strK = strK.replace('%2528','(');
					strK = strK.replace('%2B','+');	
					strK = strK.replace('%2B','+');
					strK = strK.replace('%2C',',');
					strK = strK.replace('%3B',';');
					strK = strK.replace('%3D','=');
					strK = strK.replace('%2F','/');
					strK = strK.replace('%3F','?');
					strK = strK.replace('%3A',':');
					strK = strK.replace('%26','&');
					strK = strK.replace('%20',' ');
					strK = strK.replace('%28','(');
					strK = strK.replace('%29',')');
                    strK = strK.replace('%22','"');   
                    strK = strK.replace('%2527',"'");
				    strK = strK.replace('%2529',')');
                    strK = strK.replace('%23','#');
				}

				document.getElementById('p').value = strKey;
				document.getElementById('r').value = '';
                pageflag=1;
			}
		}
		catch(ex)
		{

		}
	}

	if(document.getElementById("p") != null)
	{
	    if(document.getElementById("p").value == '')
		    document.getElementById("p").value='Business Name or Category (pizza)';
	}
	if(document.getElementById("r") != null)
	{
	   	if(document.getElementById("r").value == '' && pageflag==0)
	 	    document.getElementById("r").value='City (choose your location)';
	}
}

function combine()
{
	var str = "";
	if(document.getElementById("p").value == '')
    	document.getElementById("p").value='Business Name or Category (pizza)';
    if(document.getElementById("r").value == '')
	 	document.getElementById("r").value='City (choose your location)';

	if(document.getElementById("p").value != '' && document.getElementById("r").value != '')
	{
	      if(document.getElementById("p").value != 'Business Name or Category (pizza)'  && document.getElementById("r").value != 'City (choose your location)')	
                 str = document.getElementById("p").value + ' in ' + document.getElementById("r").value;
              else if(document.getElementById("p").value != 'Business Name or Category (pizza)')
		str = document.getElementById("p").value;
       	      else if(document.getElementById("r").value != 'City (choose your location)')
	 	str = document.getElementById("r").value;
	}
            str =str.replace('(','%28');
            str =str.replace(')','%29');
	if(document.getElementById("p").value != '' || document.getElementById("r").value != '')
	{
        if(document.getElementById("p").value != 'Business Name or Category (pizza)'  || document.getElementById("r").value != 'City (choose your location)')         
            document.getElementById("q").value = str;
	}
        var v= document.getElementById("r").value;
        v= v.replace('(','%28');
	v= v.replace(')','%29');
        document.getElementById("r").value=v;
        v=document.getElementById("p").value;
        v= v.replace('(','%28');
	v= v.replace(')','%29');
        document.getElementById("p").value=v;
}

function ponBlur()
{
	if (document.getElementById("p").value == '')
	{
		document.getElementById("p").value = 'Business Name or Category (pizza)';
	}
}

function ronBlur()
{
	if (document.getElementById("r").value == '') 
	{
		document.getElementById("r").value = 'City (choose your location)';
	}
}

function ponFocus()
{
	if (document.getElementById("p").value == 'Business Name or Category (pizza)')
	{
		document.getElementById("p").value = '';
	}
}

function ronFocus()
{
	if (document.getElementById("r").value == 'City (choose your location)')
	{
		document.getElementById("r").value = '';
	}

	setTimeout("document.getElementById('r').focus();",0); 
}


/* This Function is called from the "Search Button" Click */
/*function combine()
{
//    if(document.all)
//	{
//		event.returnValue = false;
//	}
//	else
//	{
//	    if (!e)
//        {
//            var e = window.event || arguments.callee.caller.arguments[0];            	 
//        }
//		e.preventDefault();
//		event.returnValue = false;
//	}

    if(document.getElementById("p").value == 'Business Name or Category (pizza)')
	document.getElementById("p").value='';

    if(document.getElementById("r").value == 'City (choose your location)')
	 	document.getElementById("r").value='';

	var str = "";
	if(document.getElementById("p").value != '' && document.getElementById("r").value != '')
	{
	      if(document.getElementById("p").value != 'Business Name or Category (pizza)'  && document.getElementById("r").value != 'City (choose your location)')	
                 str = document.getElementById("p").value + ' in ' + document.getElementById("r").value;
              else if(document.getElementById("p").value != 'Business Name or Category (pizza)')
		str = document.getElementById("p").value;
       	      else if(document.getElementById("r").value != 'City (choose your location)')
	 	str = document.getElementById("r").value;
	}

    str =str.replace('(','%28');
    str =str.replace(')','%29');
    //str = str.replace("'",'%27');
	if(document.getElementById("p").value != '' || document.getElementById("r").value != '')
	{
        if(document.getElementById("p").value != 'Business Name or Category (pizza)'  || document.getElementById("r").value != 'City (choose your location)')         
		    document.getElementById("q").value = str;
	}

    var v= document.getElementById("r").value;
    v = v.replace('(','%28');
	v = v.replace(')','%29');
    // v= v.replace("'",'%27');     
    document.getElementById("r").value=v;
    // alert(document.getElementById("r").value);
    v=document.getElementById("p").value;
    v= v.replace('(','%28');
	v= v.replace(')','%29');
    //  v= v.replace("'",'%27');
    document.getElementById("p").value=v;
}*/
