function ajax(url, spanid, type){
//	alert(url+"\n"+spanid+"\n");
	if(type=='float'){
		document.getElementById(spanid).className = 'show_float';
//		document.getElementById(id).className = 'show_float';
	}
	
	if(spanid == 'span_for_preload2') document.getElementById(spanid).innerHTML = preload2;
	else document.getElementById(spanid).innerHTML = preload;
	setTimeout("funcajax('"+url+"', '"+spanid+"');", 10);
//	funcajax(url, spanid)
}


function check_step1(frm){

//		alert('test');
		
		var fsub = true, err, ctr=0, fld_focus;
		var err = "The system detects the ff error: \n\n";
		
		var regex=/^([a-zA-Z0-9]){4,16}$/;
		
//		alert(frm.login_username.value.search(regex));
		
		
		if(frm.login_email.value.length < 1 || frm.login_email.value.indexOf('@') == -1 || frm.login_email.value.indexOf('.') == -1){
			if(fsub == true) fld_focus = frm.login_email;
			fsub = false;
			err += ++ctr+". Email Address must be valid \n";
		}
		
		if(frm.login_email2){
			if(frm.login_email.value != frm.login_email2.value){
				if(fsub == true) fld_focus = frm.login_email2;
				fsub = false;
				err += ++ctr+". Email Address not matched \n";
			}
		}
		
		if(frm.login_password){
			if(frm.login_password.value.length < 6){
				if(fsub == true) fld_focus = frm.login_password;
				fsub = false;
				err += ++ctr+". Password must be at least 6 characters long \n";
			}
			if(frm.login_password.value != frm.login_password2.value){
				if(fsub == true) fld_focus = frm.login_password2;
				fsub = false;
				err += ++ctr+". Password not matched \n";
			}
		}
		
		if(frm.login_firstname.value.length < 1){
			if(fsub == true) fld_focus = frm.login_firstname;
			fsub = false;
			err += ++ctr+". First Name must not be empty \n";
		}
		if(frm.login_lastname.value.length < 1){
			if(fsub == true) fld_focus = frm.login_lastname;
			fsub = false;
			err += ++ctr+". Last Name must not be empty \n";
		}
		if(frm.login_gender.value.length < 1){
			if(fsub == true) fld_focus = frm.login_gender;
			fsub = false;
			err += ++ctr+".Gender must not be empty \n";
		}
		
		//alert(document.forms['form1'].elements["login_birthdate[]"].options[0].value);
//		alert(document.forms['form1']['login_birthdate[]'].value);
//		alert(document.form1["login_birthdate[0]"].options[]);
		counter = 0;
		for($x=0; $x<frm.elements.length; $x++){
			if(frm.elements[$x].id == 'login_birthdate[]'){
				
				if(counter == 0){
					month = frm.elements[$x].value;
				}else if(counter == 1){
					day = frm.elements[$x].value;
				}else if(counter == 2){
					year = frm.elements[$x].value;
				}
				
				counter++;
			
			}
		}
		
//		document.forms['formname'].elements['elementname[]'].options
		if( !checkdate( month, day, year ) ){
			if(fsub == true) fld_focus = document.getElementById('login_birthdate[]');
			fsub = false;
			err += ++ctr+". Birthdate must be valid \n";
		}
		
		


		if(frm.login_marital_status.value.length < 1){
			if(fsub == true) fld_focus = frm.login_marital_status;
			fsub = false;
			err += ++ctr+". Marital Status must not be empty \n";
		}
		
		if(frm.login_proffesion.value.length < 1){
			if(fsub == true) fld_focus = frm.login_proffesion;
			fsub = false;
			err += ++ctr+". Profession must not be empty \n";
		}

		if(frm.login_address.value.length < 1){
			if(fsub == true) fld_focus = frm.login_address;
			fsub = false;
			err += ++ctr+". Address must not be empty \n";
		}
		if(frm.login_province.value.length < 1){
			if(fsub == true) fld_focus = frm.login_province;
			fsub = false;
			err += ++ctr+". Province must not be empty \n";
		}
		if(frm.login_city.value.length < 1){
			if(fsub == true) fld_focus = frm.login_city;
			fsub = false;
			err += ++ctr+". City must not be empty \n";
		}
		if(frm.login_zipcode.value.length < 1){
			if(fsub == true) fld_focus = frm.login_zipcode;
			fsub = false;
			err += ++ctr+". Zip Code must not be empty \n";
		}
		
		if(frm.login_telephone_1){
			
			if((frm.login_telephone_1.value.length > 1 && frm.login_telephone_2.value.length > 1) || ((frm.login_cellphone_1.value.length > 1 && frm.login_cellphone_2.value.length > 1))){
			}
			else{
				if(fsub == true) fld_focus = frm.login_telephone_1;
				fsub = false;
				err += ++ctr+". Please provide at least once contact number \n";
			}
			
		}
		

		
		
		if(frm.ihaveread){
			if(frm.ihaveread.checked != true){
				if(fsub == true) fld_focus = frm.ihaveread;
				fsub = false;
				err += ++ctr+". You must read and agree to the Terms of Service \n";
			}
		}
		
		if(frm.confirm_code){
			if(frm.confirm_code.value.length < 8){
				if(fsub == true) fld_focus = frm.confirm_code;
				fsub = false;
				err += ++ctr+". Confirm Code must be valid \n";
			}
		}
		
		
		if(fsub == false){
			alert(err);
			fld_focus.focus();
		}else{
//			registration_tab('step2');
			frm.submit();
			fsub = true;
		}
		


		return(fsub);
		

}


function checkdate( month, day, year ) {

    var myDate = new Date();
    myDate.setFullYear( year, (month - 1), day );
 
    return ((myDate.getMonth()+1) == month && day<32); 
}

function registration_tab(arg){
	
	document.getElementById('span_step1').style.display = 'none';
	document.getElementById('span_step2').style.display = 'none';
//	document.getElementById('span_step3').style.display = 'none';
	
	document.getElementById('span_'+arg).style.display = '';

	
}

var loginform = 'none';
function show_login(){
	if (loginform == 'none')
		loginform = '';
	else
		loginform = 'none';
		
	document.getElementById('login').style.display = loginform;
}



function check_user_upload(frm, arg){
	
	
		var fsub = true, err, ctr=0, fld_focus;
		var err = "The system detects the ff error: \n\n";
		
		
		
		if(frm.pgallery_title.value.length < 1){
			if(fsub == true) fld_focus = frm.pgallery_title;
			fsub = false;
			err += ++ctr+". Title must be valid \n";
		}
		

		if(frm.pgallery_image.value.length < 1 && arg != 'edit'){
			if(fsub == true) fld_focus = frm.pgallery_image;
			fsub = false;
			err += ++ctr+". Upload Photo must not be emtpy \n";
		}
		
		
		if(frm.ck_submission.checked != true){
			if(fsub == true) fld_focus = frm.ck_submission;
			fsub = false;
			err += ++ctr+". You must read and agree to the Submission Policy \n";
		}
		if(frm.ck_terms.checked != true){
			if(fsub == true) fld_focus = frm.ck_terms;
			fsub = false;
			err += ++ctr+". You must read and agree to the Terms of Service \n";
		}
		
		if(fsub == false){
			alert(err);
			fld_focus.focus();
		}else{
			registration_tab('step2');
		}
		


		return(fsub);
	
	
}




function CreateBookmarkLink(title, url) {
	 
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function check_post_comment(frm){
	var fsub = true, err, ctr=0, fld_focus;
	var err = "The ff fields must not be empty/invalid: \n\n";


	if(frm.comment_comment.value.length < 1){
		if(fsub == true) fld_focus = frm.comment_comment;
		fsub = false;
		err = "You can't send empty comment!";
	}
	
	if(fsub == false){
		alert(err);
		fld_focus.focus();
	}
	return(fsub);
}

function openwin(url, width, height){
//	alert('test');
	img = window.open (url, "mywindow","menubar=1,resizable=1,screenX=100,screenY=100,width="+width+",height="+height);
	img.focus();	
}

function star_over(arg){
	switch(arg){
		case 5:
			document.getElementById('star5').src = 'images/star1.gif';
		case 4:
			document.getElementById('star4').src = 'images/star1.gif';
		case 3:
			document.getElementById('star3').src = 'images/star1.gif';
		case 2:
			document.getElementById('star2').src = 'images/star1.gif';
		case 1:
			document.getElementById('star1').src = 'images/star1.gif';
		break;
	}
}
function star_out(arg){
	switch(arg){
		case 1:
			document.getElementById('star1').src = 'images/star0.gif';
		case 2:
			document.getElementById('star2').src = 'images/star0.gif';
		case 3:
			document.getElementById('star3').src = 'images/star0.gif';
		case 4:
			document.getElementById('star4').src = 'images/star0.gif';
		case 5:
			document.getElementById('star5').src = 'images/star0.gif';
		break;
	}
}
function star_rate(arg, id){
//	alert(arg);
//	location.replace('ratedcm.php?action=rate&star='+arg+'&id='+id);
	ajax('ratemedia.php?action=rate&star='+arg+'&id='+id, 'give_rate');
}

function star_gallery_over(arg){
	switch(arg){
		case 5:
			document.getElementById('star5').src = 'images/star_gray_1.gif';
		case 4:
			document.getElementById('star4').src = 'images/star_gray_1.gif';
		case 3:
			document.getElementById('star3').src = 'images/star_gray_1.gif';
		case 2:
			document.getElementById('star2').src = 'images/star_gray_1.gif';
		case 1:
			document.getElementById('star1').src = 'images/star_gray_1.gif';
		break;
	}
}
function star_gallery_out(arg){
	switch(arg){
		case 1:
			document.getElementById('star1').src = 'images/star_gray_0.gif';
		case 2:
			document.getElementById('star2').src = 'images/star_gray_0.gif';
		case 3:
			document.getElementById('star3').src = 'images/star_gray_0.gif';
		case 4:
			document.getElementById('star4').src = 'images/star_gray_0.gif';
		case 5:
			document.getElementById('star5').src = 'images/star_gray_0.gif';
		break;
	}
}
function star_gallery_rate(arg, id){
//	alert(arg);
//	location.replace('ratedcm.php?action=rate&star='+arg+'&id='+id);
	ajax('rate_gallery_media.php?action=rate&star='+arg+'&id='+id, 'give_rate');
}
function star_rate_eos(arg){
	
	document.getElementById('review_rate').style.display = 'none';
	document.getElementById('xreview_rate').style.display = '';

	document.getElementById('xstar5').src = 'images/star0.gif';
	document.getElementById('xstar4').src = 'images/star0.gif';
	document.getElementById('xstar3').src = 'images/star0.gif';
	document.getElementById('xstar2').src = 'images/star0.gif';
	document.getElementById('xstar1').src = 'images/star0.gif';
	
	document.getElementById('eos_rr_rate').value = arg;
	
	switch(arg){
		case 5:
			document.getElementById('xstar5').src = 'images/star1.gif';
		case 4:
			document.getElementById('xstar4').src = 'images/star1.gif';
		case 3:
			document.getElementById('xstar3').src = 'images/star1.gif';
		case 2:
			document.getElementById('xstar2').src = 'images/star1.gif';
		case 1:
			document.getElementById('xstar1').src = 'images/star1.gif';
		break;
	}
	
}

function check_review(frm){
	
		var fsub = true, err, ctr=0, fld_focus;
		var err = "The system detects the ff error: \n\n";
		
		var inst = FCKeditorAPI.GetInstance("eos_rr_content");
		var eos_rr_content = inst.GetHTML();
		
		if(frm.eos_rr_title.value.length < 1){
			if(fsub == true) fld_focus = frm.eos_rr_title;
			fsub = false;
			err += ++ctr+". Title must not be empty \n";
		}
		if(frm.eos_rr_rate.value.length < 1){
			if(fsub == true) fld_focus = frm.eos_rr_rate;
			fsub = false;
			err += ++ctr+". Product rating must be valid \n";
		}
		if(eos_rr_content.length < 25){
			if(fsub == true) fld_focus = frm.eos_rr_rate;
			fsub = false;
			err += ++ctr+". Review content must have at least 25 characters \n";
		}
		


		
		if(fsub == false){
			alert(err);
			fld_focus.focus();
		}else{
			registration_tab('step2');
		}
		


		return(fsub);
	
}

function check_comparison(){
}

function ck_login_type_photgrapher(frm, elem){
	
	
	var counter = 0;
	for($x=0; $x<frm.elements.length; $x++)
		if(frm.elements[$x].id == 'login_type_photgrapher[]' && frm.elements[$x].checked == true){
			
			counter++;
			
		}
		
		if(counter > 3){
			elem.checked = false;
			alert("Please choose type of photographer at most 3 types!");
		}
		
		
		return false;
}

function report_offensive_picture(arg){
	if(arg == 'none'){
		document.getElementById('span_offensive_photo').style.display = 'none';
	}else{
		document.getElementById('span_offensive_photo').style.display = '';
	}
}