// JavaScript Document
function alphaNumericCheck(val)
	{
		var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
		if(regex.test(val))
		{
			return true;
		} 
		else 
		{
			alert("No special charater allowed.")
			return false;
		}
	}
function checkPhoto(imagePath) 
{
	var pathLength = imagePath.length;
	var lastDot = imagePath.lastIndexOf(".");
	var fileType = imagePath.substring(lastDot,pathLength);
	
	if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")) 
	{
		return true;
	} 
	else 
	{
		alert("We support .JPG, .PNG, and .GIF image formats.");
		document.getElementById('image').focus();
		return false;
	}
}

function change_rate_over(j)
{
		//alert(10-j);
		for(i=1;i<=j;i++)
		{
			document.getElementById("rate_"+i).className="r"+j;
			//document.getElementById("rate_"+i).width=20;
			//document.getElementById("rate_"+i).height=29;
		}
		//alert(11-i);
		for(;i<=10;i++)
		{
			document.getElementById("rate_"+i).className="grey";
		}
}

function change_rate_out()
{
		for(i=1;i<=10;i++)
		{
			document.getElementById("rate_"+i).className="r"+i;
			//document.getElementById("rate_"+i).width=18;
			//document.getElementById("rate_"+i).height=27;
		}
}


function checkUrl(theUrl)
{

//alert(theUrl.value);
		if(theUrl.value=='')
			return true;
		urlStr=theUrl.value; 
		if (urlStr.indexOf(" ")!=-1)
		{
				alert("Spaces are not allowed in a URL");
				theUrl.select();
				theUrl.focus();
				return false;
		}
		if(urlStr==""||urlStr==null)
		{
				return false;
		}
		urlStr=urlStr.toLowerCase();
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var atom=validChars + '+';
		var urlPat=/^http:\/\/(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
		var matchArray=urlStr.match(urlPat);
		if (matchArray==null)
		{
			alert("URL entered incorrectly.  Please enter URL in format, e.g., 'http://www.hotflation.com'");
			theUrl.select();
			theUrl.focus();
			return false;
		}
		var user=matchArray[2];
		var domain=matchArray[3];
		for (i=0; i<user.length; i++) 
		{
			if (user.charCodeAt(i)>127) 
			{
				alert("This domain contains invalid characters.");
				theUrl.select();
				theUrl.focus();
				return false;
			}
		}
		for (i=0; i<domain.length; i++) 
		{
			if (domain.charCodeAt(i)>127) 
			{
				alert("This domain name contains invalid characters.");
				theUrl.select();
				theUrl.focus();
				return false;
			}
		}
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) 
		{
			if (domArr[i].search(atomPat)==-1) 
			{
				alert("The domain name does not seem to be valid.");
				theUrl.select();
				theUrl.focus();
				return false;
			}
		}
		if (domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
		{
			alert("The address must end in a well-known domain or two letter " + "country.");
			theUrl.select();
			theUrl.focus();
			return false;
		}
		return true;
	}
// Check Validate URL 
	/*function checkUrl(theUrl)
	{
		if(theUrl.value!='')		
		{
		  if(theUrl.value.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i) ||
			 theUrl.value.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i))
		  {
			return true;
		  } 
		  else 
		  {
			alert("Wrong URL.");
			theUrl.select();
			theUrl.focus();
			return false;
		  }
		}
		return true
}
*/
function IsBlocked(popupwin)
{
	if(!popupwin) return true;
	try
	{
		return popupwin.closed;
	}
	catch(e)
	{
		return true;
	}
 }

var mywindow=null;
function submit_me(i)
	{
		document.getElementById('rate').value=i;
		document.frm1.submit();
	}

 
  function adjust(){
	 // alert();
    width  =  0;
    height = 0;
    if( navigator.appName.indexOf("Microsoft") != -1 ){ // Microsoft
        width  = document.body.scrollWidth+126;
        height = document.body.scrollHeight+200;
    }else{
        width  = document.width+126;
        height = document.height+200;
    }

    // Put condition here
    width  = ( width  > screen.availWidth  ? screen.availWidth  : width );
    height = ( height > screen.availHeight ? screen.availHeight : height );

    x = (screen.availWidth/2)  - (width/2);
    y = (screen.availHeight/2) - (height/2);

    window.moveTo( x, y );
    window.resizeTo( width, height );
}

// pop up window with acc to your size.
function popUpWindow(url, width, height, windName){
//alert(url+"=="+width+"=="+height+"=="+windName);
    wind = window.open(url, (windName ? windName : "_sameWindow"), "width=" +width+ ",height=" +height+ ",scrollbars=yes");
    x = (screen.availWidth/2)  - (width/2);
    y = (screen.availHeight/2) - (height/2);
  wind.moveTo(x, y);
   // wind.resizeTo( width, (height+23) );
    wind.focus();
}
 
 
function closer() 
{
	opener.location.reload(true);
	self.close();
}

function chk_user()
{
	var username=document.getElementById('username1').value;
	//alert(document.getElementById('username1').value);
	if(document.getElementById('username1').value==='')
	{
		alert("Please Enter Username!");
		document.getElementById('username1').focus();
		return false;
	}
	else
	{
		document.getElementById('results').innerHTML='<img src=images/ajax_loader.gif>';
	}
	
	new Ajax.Updater('results','chk_avaliable.php?username='+username,{evalScripts:true});
}

function custmize_widget(pic,color1)
{
//	alert(color);
	var url_para='pic='+pic+'&bgcolor='+color1;
//	alert(url_para);
//	return false;
	document.getElementById('results').innerHTML='<img src=images/ajax_loader.gif>';
	new Ajax.Updater('results','widget.php?'+url_para,{evalScripts:true});
}

function show_code(pic)
{
		var default_color='';
	for(i=1;i<=4;i++)
	{
		if(document.getElementById('color'+i).checked==true)
		{
			//alert(default_color=document.getElementById('color'+i).value);
			default_color=document.getElementById('color'+i).value;
			break;
		}
	}
		if(document.getElementById('color5').value!='')
		{
			default_color=document.getElementById('color5').value;

		}
	
	//alert(default_color);
	var url_para='pic='+pic+'&bgcolor='+default_color;
	document.getElementById('result1').innerHTML='<img src=images/ajax_loader.gif>';
	new Ajax.Updater('result1','widget_code.php?'+url_para,{evalScripts:true});		
}

function newacc_validate()
{
	
	if(document.getElementById('username1').value==='')
	{
		alert("Please Enter Username!");
		document.getElementById('username1').focus();
		return false;
	}
	flag=alphaNumericCheck(document.getElementById('username1').value);
		if(flag==false)
		{
			document.getElementById('username1').focus();
			return false;	
		}
	len=document.getElementById('username1').value.length;
	//alert(len);
	if(len<4 || len>20)
	{
		alert("Please enter a username between 4 and 20 characters long!");
		document.getElementById('username1').focus();
		return false;
	}
	
	
	if(document.getElementById('password1').value=='')
	{
		alert("Please enter Password");
		document.getElementById('password1').focus();
		return false;
	}
	
	len=document.getElementById('password1').value.length;
	//alert(len);
	if(len<6 || len>40)
	{
		alert("Please enter a password between 6 and 40 characters long!");
		document.getElementById('password1').focus();
		return false;
	}
	
	if(document.getElementById('cpassword').value=='')
	{
		alert("Please enter Confirm password");
		document.getElementById('cpassword').focus();
		return false;
	}
	if(document.getElementById('password1').value!=document.getElementById('cpassword').value)			
	{
		alert("Password and confirm password do not match");
		document.getElementById('password1').focus();
		return false;			
	}
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))) 
	{
		alert("Please correct your email address");
		document.getElementById('email').focus();
		return false;
	}
	if(document.getElementById('verifiction_code').value=='')
	{
		alert("Please enter the verification code");
		document.getElementById('verifiction_code').focus();
		return false;
	}
	if(document.getElementById('agree').checked==false)
	{
		alert("Please read and accept our Terms of Use and Privacy Policy");
		document.getElementById('agree').focus();
		return false;
	}
	
	return true;	
}

	function share_links()
	{
		var arr = new Array();
		if(document.getElementById('to_email').value=='')
		{
			alert("Please enter recipient's email address");
			document.getElementById('to_email').focus();
			return false;	
		}
		
		if(document.getElementById('from_email').value=='')
		{
			alert("Please enter your email address");
			document.getElementById('from_email').focus();
			return false;	
		}
		
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('from_email').value))) 
		{
			alert("Please correct your email address");
			document.getElementById('from_email').focus();
			return false;
		}


		             arr=document.getElementById('to_email').split(",");
                for(mail in arr)
                {
                        if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)))
                        {
                                alert(mail+" is not a valid email address. Please correct this.");
                                document.getElementById('to_email').focus();
                                return false;
                        }
                }		
		//return false;	
		return true;



	}
	
	function upload_validate()
	{
		if(document.getElementById('image').value=='')
		{
			alert("Please enter image");
			document.getElementById('image').focus();
			return false;
		}		
		return true;
	}
	function upload_validate_1()
	{
		if(document.getElementById('image_1').value=='')
		{
			alert("Please enter image url");
			document.getElementById('image_1').focus();
			return false;
		}		
		return true;
	}
	function forgot_pass()
	{
		if(document.getElementById('email').value=='')
		{
			alert("Please enter email address");
			document.getElementById('email').focus();
			return false;
		}
		return true;
	}
	
	function login_validate()
	{
		if(document.getElementById('username1').value=='')
		{
			alert("Please enter username");
			document.getElementById('username1').focus();
			return false;
		}
		 
		flag=alphaNumericCheck(document.getElementById('username1').value);
		if(flag==false)
		{
			document.getElementById('username1').focus();
			return false;	
		}
		
		
		if(document.getElementById('password1').value=='')
		{
			alert("Please enter password");
			document.getElementById('password1').focus();
			return false;
		}
		return true;
	}
	
	
	function login_validate1()
	{
		
		
		if(document.getElementById('username').value=='')
		{
			alert("Please enter username");
			document.getElementById('username').focus();
			return false;
		}
		 
		flag=alphaNumericCheck(document.getElementById('username').value);
		if(flag==false)
		{
			document.getElementById('username').focus();
			return false;	
		}
		
		if(document.getElementById('password').value=='')
		{
			alert("Please enter password");
			document.getElementById('password').focus();
			return false;
		}
		return true;
	}
	
function  focus_small(){
	if(mywindow!=null)
      mywindow.focus();
	
	}
	
	function src_validate()
	{
		if(document.getElementById('query').value=='')
		{
			alert("Please enter some keywords to search.");
			document.getElementById('query').focus();
			return false;
		}

		if(document.getElementById('query').value.length<3)
		{
			alert("Please enter atleast 3 characters as a keywords to search.");
			document.getElementById('query').focus();
			return false;
		}
		return true;
	}
	
	
