/***********************************************
* Drop Down Date select script- by JavaScriptKit.com
* This notice MUST stay intact for use
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
***********************************************/
var player = null;

var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

function validateFormOnSubmit(form) {
	var reason = "";
	
	reason += validateField(form.descrip);
	reason += validateField(form.image);
	
	if ( reason != "" ) {
		alert("This fields are required.\n");
		return false;
	}
	
	alert("Thank you for submitting.");
	return true;
}

function validateField(fld) {
	var error = "";
	var illegalChars = /\W/; // allow letters, numbers, and underscores		
	if (fld.value == "") {
		error = " ";
		fld.style.background = 'Yellow';
	} else {
		fld.style.background = 'White';
	}
	return error;
}

function Disab() 
{
	frm=document.forms['drop_list']
	if(frm.vid.value != "" & frm.cboCountry.selectedIndex != "" & frm.cboState.selectedIndex != "" & frm.order.selectedIndex != "" & frm.cbocategory.selectedIndex != "" & 	frm.cat.selectedIndex != "" & frm.brand.value != "" & frm.descrip.value != "" & frm.tags.value != "" & frm.image.value != "")
	{frm.Button1.disabled=false}
	else {frm.Button1.disabled=true}
}

function DisabPromoReg() 
{
	frm=document.forms['form']
	if(frm.agree.checked)
	{
		frm.Button1.disabled = false;
	}
	else 
	{
		frm.Button1.disabled = true;
	}
}

function DisabReg() {
	frm=document.forms['form']
	if(frm.agree.checked)
	{frm.Button1.disabled=false}
	else {frm.Button1.disabled=true}
}
//////////////////////////////////////////////////////
function validateFormOnSubmitAdUp(form) 
{
	var reason = "";

  reason += validateUsername(form.link);
  reason += validateUsername(form.image);
  reason += validateUsername(form.order);
	reason += validateURL(form.site);
      
  if (reason != "") {
    alert("All fields are required.\n");
    return false;
  }

  alert("Thank you for submitting.");
  return true;
}

function validateFormOnSubmitPrUp(form) {
var reason = "";

  reason += validateUsername(form.vid);
  reason += checkDropdown(form.cboCountry);
  reason += checkDropdown(form.cboState);
  reason += checkDropdown(form.cbocategory);
  reason += checkDropdown(form.cat);
  reason += checkDropdown(form.order);
  reason += validateUsername(form.brand);
  reason += validateUsername(form.descrip);
  reason += validateUsername(form.tags);
  if ( form.image.value == '' && form.embedcode.value == '' ) {
	reason += validateUsername(form.image);
	}
      
  if (reason != "") {
    alert("All fields are required.\n");
    return false;
  }
  document.getElementById("java").innerHTML="<br />Please wait while your video uploads.";
  document.getElementById("java").style.visibility = "visible";
  alert("Thank you for submitting.");
  return true;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if (fld.value == "") {
		error = " ";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
    } else if ((fld.value.length < 6) || (fld.value.length > 15)) {
        error = "The password must be between 6 and 15 characters. \n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

/* vozmojno ne ispol'zuetsya */
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}

function validatePhoneRegPromo(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } //else if (!(stripped.length == 10)) {
        //error = "The phone number is the wrong length. Make sure you included an area code.\n";
        //fld.style.background = 'Yellow';
    //}
    return error;
}

function passwordMatch()
{
  var frm = document.forms["form"];
  if(frm.pass1.value != frm.pass2.value) {
  	frm.pass2.style.background = 'Yellow';
    alert('The Password and verified Password fields do not match');
    return false;
  }
  else
  {
  	frm.pass2.style.background = 'White';
    return true;
  }
}

function emailMatch()
{
  var frm = document.forms["form"];
  if(frm.email.value != frm.email2.value) {
  	frm.email2.style.background = 'Yellow';
    alert('The eMail and verified eMail fields do not match!');
    return false;
  }
  else
  {
  	frm.email2.style.background = 'White';
    return true;
  }
}

/********************************/
function checkDropdown(choice) {
    var error = "";
	thing = choice.value;
    if (thing == "") {
		error = " "
	   choice.style.background = 'Yellow';
    }else{
	choice.style.background = 'white';
}
	return error;
}
/* byla v fayle adupload.php 
function checkDropdown(choice) {
    var error = "";
    if (choice.selectedIndex.value = "") {
	   choice.style.background = 'Yellow';
	   return false;
    }   
}
/********************************/

function CheckTextbox(elem, nsym) 
{
	if ( elem.value.length > nsym ) 
	{
		elem.value = elem.value.substr(0, nsym);
		alert('This field must contain maximum ' + nsym + ' chars');
	}
}

function CheckTextboxSpAd(elem, nsym) 
{
	if ( elem.value.length > nsym ) 
	{
		elem.value = elem.value.substr(0, nsym);			
	}
	var counter = document.getElementById('ch_count');
	counter.innerHTML = nsym - elem.value.length;
}
	
function validateURL(fld)
{
	error = "";
	site = fld.value;
	parts = site.split(".");
	count = 0;
	while( count < parts.length)
	{
		count+=1;
	}
	check = parts[0].indexOf("http://");
	sum = count + check;
	
	if (sum != 3) 
	{
		error = " ";
		alert('The proper form of a url is http://www.mysite.com');
		fld.style.background = 'Yellow';
		return error;
	} 
	else 
	{
		fld.style.background = 'White';
		return error;
	}
}

function validateURLRegPromo(fld)
{
	error = "";
	site = fld.value;
	parts = site.split(".");
	count = 0;
	while( count < parts.length)
	{
		count+=1;
	}
	check = parts[0].indexOf("http://www");
	
	if(check == 0)
	{
		check+=1;
	}
	else
	{
		check=0;
	}
	sum = count + check;
	count+=1;
	
	if (sum != count) 
	{
		error = " ";
		alert('The proper form of a url is http://www.mysite.com');
		fld.style.background = 'Yellow';
		return error;
	} 
	else 
	{
		fld.style.background = 'White';
		return error;
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function popitup(url) {
	newwindow=window.open(url,'name','height=750,width=550,scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

function gup( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
	return "";
	else
	return results[1];
}

function playABS420() {
	player = document.getElementById("player");
	//alert("player = " + player);
	addListeners();
}
	
function addListeners() {
	if (player && player.addModelListener) { 
		//alert(player);
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}
	
function stateListener(obj,vid) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 

//	if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
//		document.location.href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player"; 
//		
//	}

	if ( currentState == "PLAYING" ) {
		var vid4 = vid ? vid : 'null';
		htmlData(vid4);
		//alert(vid4);
		
		//htmlData(vid);
		//alert(vid);
		
			
	}
}

function GetXmlHttpObject(handler) 
{
	var objXMLHttp=null;
	if ( window.XMLHttpRequest ) 
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if ( window.ActiveXObject ) 
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
	{
		if ( xmlHttp.responseText != "" ) {
			document.getElementById("txtResult").innerHTML = xmlHttp.responseText;
		}
		//alert(xmlHttp.responseText);
		//top.frames["LMSFrame"].sco_id = xmlHttp.responseText;
		//top.glbSCOID= xmlHttp.responseText;
		//alert("sco = " + top.glbSCOID);
	}
	else {
		//alert(xmlHttp.status);
	}
}

function stateChangedMemComp()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert(xmlHttp.responseText + 'Sorry, no service available at this time, you may want to try another member.');
		//top.frames["LMSFrame"].sco_id = xmlHttp.responseText;
		top.glbSCOID = xmlHttp.responseText;
		//alert(xmlHttp.readyState);
		//alert("sco = " + top.glbSCOID);		
	}
	else {
		//alert(xmlHttp.status);
	}
}

function htmlDataMemComp(vid)
{
	//if (url.length==0)
	//{
	//document.getElementById("txtResult").innerHTML="";
	//return;
	//}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return false;
	}
	
	url="sendemail.php?email="+vid; 
	url=url+"&ripanid="+Math.random();
	
	alert('Sorry, no service available at this time, you may want to try another member.');
	//alert("Frame = " + url);
	xmlHttp.onreadystatechange = stateChangedMemComp;
	xmlHttp.open("GET",url,false) ;
	xmlHttp.send(null);
	return false;
}

function htmlData(vid) {
	xmlHttp = GetXmlHttpObject();
	if ( xmlHttp == null ) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	url = "test.php?vid=" + vid + "&sid=" + Math.random();
	//alert("Frame = " + url);
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function msg()
{
	alert('Sorry, no service available at this time, you may want to try another member.');
}

function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}

function validateFormOnSubmitReg(form) 
{
	var reason = "";
  reason += validateUsername(form.user);
  reason += validateUsername(form.fname);
  reason += validateUsername(form.lname);
  reason += validatePassword(form.pass1);
  reason += validatePassword(form.pass2);
  reason += validateUsername(form.word);
  reason += validateEmail(form.email);
  reason += validateEmail(form.email2); 
  reason += checkDropdown(form.cboCountry);
  reason += checkDropdown(form.birth1);
  reason += checkDropdown(form.birth2);
  reason += checkDropdown(form.birth3);
      
  if (reason != "") {
    alert("All fields are required.\n");
    return false;
  }

  alert("Thank you for submitting.");
  return true;
}

function validateFormOnSubmitRegPromo(form) {
	var reason = "";
  reason += validateUsername(form.compname);
  reason += validateUsername(form.fname);
  reason += validateUsername(form.lname);
  reason += validateUsername(form.title)
  reason += validateUsername(form.address1);
  reason += validateUsername(form.address2);
  reason += validateUsername(form.address3);
  reason += validateUsername(form.address4);
  reason += validateUsername(form.address5);
  reason += validateUsername(form.mailaddress1);
  reason += validateUsername(form.mailaddress2);
  reason += validateUsername(form.mailaddress3);
  reason += validateUsername(form.mailaddress4);
  reason += validateUsername(form.mailaddress5);
  reason += validateUsername(form.area);
  reason += validatePhoneRegPromo(form.phone);
  reason += validateUsername(form.altarea);
  reason += validatePhoneRegPromo(form.altphone);
  reason += validateEmail(form.email);
  reason += validateEmail(form.email2);
  reason += validateURLRegPromo(form.site);
  reason += validateUsername(form.user);
  reason += validatePassword(form.pass1);
  reason += validatePassword(form.pass2);
  reason += validateUsername(form.word);

      
  if (reason != "") {
    alert("All fields are required.\n");
    return false;
  }

  alert("Thank you for submitting.");
  return true;
}

function validateFormOnSubmitUserUpl(form) 
{
	var reason = "";

  reason += validateUsername(form.vid);
  reason += checkDropdown(form.cboCountry);
  reason += checkDropdown(form.cboState);
  reason += checkDropdown(form.cat);
  reason += validateUsername(form.descrip);
  reason += validateUsername(form.tags);
  if ( form.image.value == '' && form.embedcode.value == '' ) {
	reason += validateUsername(form.image);
	}
      
  if (reason != "") {
    alert("All fields are required.\n");
    return false;
  }
	document.getElementById("java").innerHTML="<br />Please wait while your video uploads.";
	document.getElementById("java").style.visibility = "visible";
  alert("Thank you for submitting.");
  return true;
}

function populatedropdown(dayfield, monthfield, yearfield)
{	
	var today=new Date();
	var dayfield=document.getElementById(dayfield);
	var monthfield=document.getElementById(monthfield);
	var yearfield=document.getElementById(yearfield);
	
	for (var i=0; i<31; i++)
	{		
		dayfield.options[i]=new Option(i+1, i+1);
	}
	//dayfield.options[32]=new Option("", "", true, true); //select today's day
	
	for (var m=0; m<12; m++)
	{
		monthfield.options[m]=new Option(monthtext[m], monthtext[m]);
	}
	//monthfield.options[13]=new Option("", "", true, true); //select today's month
	
	var thisyear=today.getFullYear();
	for (var y=0; y<100; y++)
	{
		yearfield.options[y]=new Option(thisyear, thisyear);
		thisyear-=1;
	}
	//yearfield.options[101]=new Option("", "", true, true); //select today's year
}

function textcopy(){
var x = document.getElementById("phone").value;
document.getElementById("altphone").value = x;
}

function addresscopy(){
var x1 = document.getElementById("Company Address1").value;
var x2 = document.getElementById("Company Address2").value;
var x3 = document.getElementById("Company Address3").value;
var x4 = document.getElementById("Company Address4").value;
var x5 = document.getElementById("Company Address5").value;
document.getElementById("Mailing Address1").value = x1;
document.getElementById("Mailing Address2").value = x2;
document.getElementById("Mailing Address3").value = x3;
document.getElementById("Mailing Address4").value = x4;
document.getElementById("Mailing Address5").value = x5;
}

function flashLoad(adbanner)
{		//alert(adbanner);
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = "world";
	if(document.getElementById('myAlternativeContent'))
	{
		swfobject.embedSWF(site_url+"includes/world.swf", "myAlternativeContent", "320", "175", "9.0.0", false, flashvars, params, attributes);
	}

	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = "cascade";		
	if(document.getElementById('myAlternativeContent3'))
	{
		swfobject.embedSWF(site_url+"includes/cascade.swf", "myAlternativeContent3", "200", "400", "9.0.0", false, flashvars, params, attributes);
	}
	
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = "cascade2";
	if(document.getElementById('myAlternativeContent2'))
	{
		swfobject.embedSWF(site_url+"includes/cascade2.swf", "myAlternativeContent2", "200", "400", "9.0.0", false, flashvars, params, attributes);
	}
	
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};
	if(''!=adbanner) 
	{	
		attributes.id = "adbanner"+adbanner;
		if(document.getElementById('myAlternativeContent4'))
		{
			swfobject.embedSWF(site_url+"includes/adbanner_"+adbanner+".swf", "myAlternativeContent4", "800", "120", "9.0.0", false, flashvars, params, attributes);
		}
	}
	
	var flashvars = {};
	var params = {};
	params.menu = "false";
	var attributes = {};
	attributes.id = "promo-reel";
	if(document.getElementById('myAlternativeContent6'))
	{
		swfobject.embedSWF(site_url+"includes/reel/promoreel.swf", "myAlternativeContent6", "300", "80", "9.0.0", false, flashvars, params, attributes);
	}
	
	var flashvars = {};
	var params = {};
	params.menu = "false";
	var attributes = {};
	attributes.id = "user-reel";
	if(document.getElementById('myAlternativeContent5'))
	{
		swfobject.embedSWF(site_url+"includes/reel/userreel.swf", "myAlternativeContent5", "300", "80", "9.0.0", false, flashvars, params, attributes);
	}
	
	var t = setTimeout("window.location.hash='scroll'", 8000);
}

function fillCountryList()
{
     htmlData();
// Get country element ID
    var countryList = document.getElementById("cboCountry");

    // Clear any current values in select box
    // If JavaScript isn't working existing text will remain
    for (var x = countryList.options.length-1; x >-1; x--)
    {
        countryList.options[x] = null;
    }
    // Fill Country name Array from XML file
    var countryNames = xmlDoc.getElementsByTagName("country");
    // Gets total Number of countries in XML file
    var numberOfCountries = countryNames.length;

    // Loop through Country name Array and populate country select
    for (var i=0; i<=numberOfCountries-1; i++)
    {
        var currentCountry =  countryNames[i].getAttribute("name");
        fillList(countryList,currentCountry,currentCountry);
    }
}

function HideMsgJSDisabled()
{
	var objBlock = document.getElementById('msg_js_disabled');
	if(objBlock)
	{
		objBlock.style.display = 'none';
	}
}

function validateFormOnSubmitPromoReg(form) 
{
	var reason = "";
  reason += validateUsername(form.compname);
  reason += validateUsername(form.fname);
  reason += validateUsername(form.lname);
  reason += validateUsername(form.title)
  reason += validateUsername(form.address1);
  reason += validateUsername(form.address2);
  reason += validateUsername(form.address3);
  reason += validateUsername(form.address4);
  reason += validateUsername(form.address5);
  reason += validateUsername(form.mailaddress);
  reason += validateUsername(form.mailaddress2);
  reason += validateUsername(form.mailaddress3);
  reason += validateUsername(form.mailaddress4);
  reason += validateUsername(form.mailaddress5);
  reason += validatePhoneRegPromo(form.phone);
  reason += validatePhoneRegPromo(form.altphone);
  reason += validatePhoneRegPromo(form.countrycode);
  reason += validatePhoneRegPromo(form.countrycode2);
  reason += validatePhoneRegPromo(form.countrycodealt);
  reason += validatePhoneRegPromo(form.countrycodealt2);
  reason += validateEmail(form.email);
  reason += validateEmail(form.email2);
  reason += validateURL(form.site);
  reason += validateUsername(form.user);
  reason += validatePassword(form.pass1);
  reason += validatePassword(form.pass2);
  reason += validateWord(form.word);
      
  if (reason != "") {
    alert("All fields are required.\n" + reason);
    return false;
  }
  alert("Thank you for submitting.");
  return true;
}

function validateWord(fld) {
    var error = "";
   //alert(fld);
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if (fld.value == "") {
		error = "";
        fld.style.background = 'Yellow';
		error = "Please enter Secret Word  \n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function showHideBlock(idBlock)
{
	var objBlock = document.getElementById(idBlock);
	if(objBlock)
	{
		if(objBlock.className == 'display_none')
		{
			objBlock.className = 'display';
		}
		else
		{
			objBlock.className = 'display_none';
		}
	}
	
	return false;
}