// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

// right click 
			var message="The entire content on this site is protected by copyright, trademark rights and database rights.\nNo reproduction without the consent of the relevant owner.\n AscendCasting Inc. Copyright 2005-2006";
			function clickIE4(){
				if (event.button==2){
					alert(message);
					return false;
				}
			}
			function clickNS4(e){
				if (document.layers||document.getElementById&&!document.all){
					if (e.which==2||e.which==3){
						alert(message);
						return false;
					}
				}
			}
			if (document.layers){
				document.captureEvents(Event.MOUSEDOWN);
				document.onmousedown=clickNS4;
			}
			else if (document.all&&!document.getElementById){
				document.onmousedown=clickIE4;
			}
			document.oncontextmenu=new Function("alert(message);return false")
// end right click 

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer >= 3) browserVer = "1";
else if (browserName == "Microsoft Internet Explorer" && browserVer == 4) browserVer = "1";
else browserVer = "2";

//preload images:
if (browserVer == 1) {
btntln_on = new Image(80,15);
btntln_on.src = "images/add_talent_o.gif";
btntln_off = new Image(80,15);
btntln_off.src= "images/add_talent_r.gif";

btnproj_on = new Image(80,15);
btnproj_on.src = "images/add_project_o.gif";
btnproj_off = new Image(80,15);
btnproj_off.src= "images/add_project_r.gif";
}

//image swapping function:

function hiLite(imgDocID, imgObjName, comment) {
/*
alert(imgDocID);
alert(imgObjName);
alert(comment);
alert(document.images[imgDocID].src);
*/

if (browserVer == 1) {
document.images[imgDocID].src = eval(imgObjName + ".src");
window.status = comment; return true;
}}


function testtype(which)
{
	//alert('hello');
	//alert(which.name+"_on.src");
	//alert(eval(which.name+"_on.src"));
	//alert(which.type);
	//alert(which.name);
	//alert(which.src);
	//which.src = eval(which.name+"_on.src");
}

function btnon(which)
{
	/*
	alert('hello on');
	alert(which.name+"_on.src");
	alert(eval(which.name+"_on.src"));
	alert(which.type);
	alert(which.name);
	alert(which.src);
*/
which.src = eval(which.name+"_on.src");
}

function btnoff(which)
{
/*	alert('hello off');
	alert(which.name+"_on.src");
	alert(eval(which.name+"_on.src"));
	alert(which.type);
	alert(which.name);
	alert(which.src);
*/
	which.src = eval(which.name+"_off.src");
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkrequired(which){
var pass=true
// alert('checkrequired');
// password1 and password2 should be same
var passstring1 = "123"
var passstring2 = "123"
var pp=1
if (document.images)
{
	for (i=0;i<which.length;i++)
	{
		var tempobj=which.elements[i]
		//alert(tempobj.type);
		if(tempobj.type=="password")
		{
			//alert(tempobj.name);
			if(pp==1)
			{
			passstring1=tempobj.value
			pp=2
			}
			else
			{
			passstring2=tempobj.value
			}
		}
	}
}

//alert(passstring1)
//alert(passstring2)
if(passstring1 != passstring2)
{
	alert("Password are not identical.")
	return false
}

//alert(document.getElementById('requiredphone1').value);
if (document.getElementById('requiredphone1').value==""){
	alert("Please Enter your Phone Number")
	return false
}
if (checkInternationalPhone(document.getElementById('requiredphone1').value)==false){
	alert("Please Enter a Valid Phone Number")
	return false
}

if(document.getElementById('totalcharge').value==0) // free registeration
{
alert('You are registering as a free Actor.');
//alert(document.getElementById('totalcharge').value);
	return true;
}

if(isNaN(document.getElementById('requiredcc_number').value)||isNaN(document.getElementById('requiredcc_verification').value))
{
	alert('Credit Card and Verification Code should be Numeric.');
	pass=false;
	//return false;
}

/*
if(document.getElementById('totalamount').value=="0")
{
	alert('Shopping Cart Empty. Can not check out');
	return false;
}
*/
if (document.images)
{
	for (i=0;i<which.length;i++)
	{
		var tempobj=which.elements[i]
		//alert(tempobj.type);
		if(tempobj.type=="checkbox"&&!tempobj.checked)
		{
			//alert(tempobj.checked);
			//alert(tempobj.value);
			//pass=false
			//break
		}
		else
		{
			//alert(tempobj.value);
		}
	}
}
if (document.images)
{
	for (i=0;i<which.length;i++)
	{
		var tempobj=which.elements[i]
		//alert(tempobj.name);
		if (tempobj.name.substring(0,8)=="required")
		{
			if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)||(tempobj.type=="checkbox"&&!tempobj.checked))
			{
				//alert(tempobj.type);
				//alert(tempobj.checked);
				//alert(tempobj.value);
				pass=false
				break
			}
		}
	}
}



if (!pass)
{
	alert("Please complete all required fields.")
	return false
}
else
	if(testCreditCard())
	{
	//alert('yes');
	return true;
	}
	else
	{
	alert('Credit Card information not correct. Please correct and try again.');
	return false;
	}
}


function SelectPicture(nuserid,curpic)
{
	//alert(nuserid);
	//alert(curpic);
	options = "toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,width=300,height=600";
	url = "talentselectpicture.php?userid="+nuserid+"&picused="+curpic;
	//alert(url);
	newwindow=window.open(url,"mywindow", options);
}


function MyHtmlWindow(fname,width,height) {
//Define contents of page
//Create new Window
// <a href="javascript:MyHtmlWindow('images/gallery_1.jpg',680,540)">

options = "toolbar=0,status=0,menubar=0,scrollbars=1," +
"resizable=0,width="+
width+
",height="+
height;
newwindow=window.open(fname,"mywindow", options);
}


/*============================================================================*/
var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {
//alert(cardnumber);
//alert(cardname);
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};

//alert('still here1');
  // Establish card type
  var cardType = -1;
  for (i=0; i<cards.length; i++) {
//alert(i);
//alert(cards.length);
    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
//alert('still here2');
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
//alert('still here3');
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
//alert('still here4');
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
//alert('still here5');
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  
//alert('still here6');

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
//alert('still here7');
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
//alert('still here8');
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
//alert('still here9');
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
//alert('still here10');
  
  // The credit card is in the required format.
  return true;
}

/*============================================================================*/


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function rollover() 
{
  if (!document.getElementById) return
  var imgOrSrc;
  var imgPreload = new Array();
  var images = document.getElementsByTagName('img');
  for (var i = 0; i < images.length; i++) {
    if (images[i].getAttribute('rsrc')) {
      imgPreload[i] = new Image();
      imgPreload[i].src = images[i].getAttribute('rsrc');
      images[i].onmouseover = function() {
        imgOrSrc = this.getAttribute('src');
        this.setAttribute('src',this.getAttribute('rsrc'))
      }
      images[i].onmouseout = function() {
        this.setAttribute('src',imgOrSrc)
      }
    }
  }
}


// for loaing .... section START
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {
if ((appName=='Netscape')&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
}
} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
}
MM_reloadPage(true);
function MM_findObj(n, d) { //v4.0
var p,i,x;
if(!d) d=document; if((p=n.indexOf('?'))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
}
if(!(x=d[n])&&d.all) 
x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById)
x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
if ((obj=MM_findObj(args[i]))!=null) {
v=args[i+2];
if (obj.style) {
obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;
}
obj.visibility=v;
}
}

var clicks=true;
function toggle(layer){
MM_showHideLayers(layer,'',clicks?'hide':'show'); clicks=!clicks;
}
// for loaing .... section END

function _CF_hasValue(obj, obj_type)
    {
	    if (obj_type == "TEXT" || obj_type == "PASSWORD")
		{
	    	if (obj.value.length == 0) 
	      		return false;
      		return true;
	    	}
	    else if (obj_type == "SELECT")
		{
	        if (obj.selectedIndex > 0)
				return true;
       		return false;	
		}
	    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
		{
			if (obj.checked)
				return true;
       		return false;	
		}
	    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
		{
	        for (i=0; i < obj.length; i++)
		    	{
				if (obj[i].checked)
					return true;
				}
	       	return false;	
		}
	}


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
	   var strValidChars = "0123456789.-";
	   var strChar;
	   var blnResult = true;
	   if (strString.length == 0) return false;
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
	      {
	      strChar = strString.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	         blnResult = false;
	         }
	      }
	   return blnResult;
   }

function ValidateNumeric(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

else
   return false;
}


function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


